Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint config gets linked or copied depending on where it comes from #40

Merged
merged 5 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can also run them with `node_modules/.bin/kyt commandName`
3. `run` runs production code
4. `test` runs AVA on all tests in /src
5. `proto` starts the prototyping app
6. `lint` lints src code using eslint
6. `lint` lints src code using ESlint
7. `help` shows commands and their documentation
8. `setup` sets up kyt and installs a specified [starter-kyt](/Starterkyts.md)

Expand All @@ -33,7 +33,10 @@ kyt test looks for any `*.test.js` files in `src/`.

### lint
The `lint` command lints all files in the src directory using eslint.
You can override the base eslint file in the kyt config.
During setup, an ESLint config is copied into the root of your repo.
You can add or update any rules from this file.

kyt's ESLint config extends [Airbnb](https://github.com/airbnb/javascript)

stylelint details TK.

Expand All @@ -51,6 +54,7 @@ The command has two options:
1. Clone the repo for your starter
2. Install necessary npm packages
3. Copy configuration and src
4. Add kyt commands to your npm scripts
4. Copy lint configs into your root
5. Add kyt commands to your npm scripts

After that you're ready to build.
30 changes: 10 additions & 20 deletions cli/actions/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CLIEngine = require('eslint').CLIEngine;
const temp = require('temp');
const fs = require('fs');
const merge = require('ramda').merge;
const shell = require('shelljs');
const logger = require('./../logger');
const kytConfig = require('./../../config/kyt.config');
const baseConfig = require('./../../eslint.json');
Expand Down Expand Up @@ -41,25 +42,14 @@ module.exports = () => {
logger.log(formatter(report.results));
};

// In order to support merging a local configFile/eslint.json,
// we need to save the result of the merge to a temp file
// and point to that. Otherwise, we just use our config.
if (kytConfig.eslintConfig) {
const config = getConfig(kytConfig.eslintConfig);
temp.open('temp-eslintrc-', (error, info) => {
if (!error) {
fs.write(info.fd, JSON.stringify(config));
fs.close(info.fd, logger.error);
eslintCLI.configFile = info.path;
lint();
temp.cleanupSync();
logger.info('Using eslint config override');
} else {
logger.error('Error with user eslint config', error);
}
});
} else {
eslintCLI.configFile = path.join(__dirname, '../../eslint.json');
const esLintPath = path.join(kytConfig.userRootPath, './eslint.json');

// Check to see if eslint file exists
if (!shell.test('-f', esLintPath)) {
logger.error('You do not have an esLint File');
logger.info('Run node_modules/.bin kyt setup to get the default eslint config');
process.exit();
}
eslintCLI.configFile = esLintPath;
lint();
}
};
30 changes: 28 additions & 2 deletions cli/actions/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,32 @@ module.exports = (program) => {
logger.task('Installed new modules');
};

// Creates a symbolic link from our local
// Create an eslint.json in the user's base directory
const createEsLintLink = () => {
const tmpEsLint = path.join(tmpDir, 'eslint.json');
const linkedPath = path.join(userRootPath, 'eslint.json');

// Backup esLint if it exists
if(shell.test('-f', linkedPath)) {
const eslintBackup = path.join(userRootPath, `eslint-${Date.now()}-bak.json`);
shell.exec(`mv ${linkedPath} ${eslintBackup} `);
logger.task(`Backed up current eslint file to: ${eslintBackup}`);
}

// Copy over starter-kyt esLint
if (shell.test('-f', tmpEsLint)) {
if (shell.cp(tmpEsLint, linkedPath).code === 0 ) {
logger.task('Copied ESLint config from starter-kyt');
}
} else {
// Copy our local eslint
const esLintPath = path.join(userRootPath, 'node_modules/kyt/eslint.json');
if (shell.cp(esLintPath, linkedPath).code === 0) {
logger.task('Copied kyt default ESLint config');
}
}
};

// .editorconfig to the user's base directory.
const createEditorconfigLink = () => {
const editorPath = './node_modules/kyt/.editorconfig';
Expand Down Expand Up @@ -172,12 +197,13 @@ module.exports = (program) => {
}
// Copy the prototype file from the starter kit into the users repo
shell.exec(`cp ${starterProto} ${userProto}`);
logger.task('copied prototype.js file into root');
logger.task('Copied prototype.js file into root');
};

try {
updateUserPackageJSON();
installUserDependencies();
createEsLintLink();
createEditorconfigLink();
createKytConfig();
createPrototypeFile();
Expand Down
5 changes: 2 additions & 3 deletions config/kytConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ See the [base kyt config](/config/kyt.base.config.js) for an example.
2. `clientPort` - port for the client assets server *default*: 3001
3. `prototypePort` - port for the prototyping dev server *default*: 3002
4. `debug` - when true, the CLI returns all verbose output *default*: false
5. `eslintConfig` - a path to a new eslintConfig, which overrides kyt's default
6. `productionPublicPath` - the public path for assets in the production build. Useful for CDN's *default*: `/assets/`
7. `modifyWebpackConfig` - the callback function that allows you to edit webpack configs. See more details below
5. `productionPublicPath` - the public path for assets in the production build. Useful for CDN's *default*: `/assets/`
6. `modifyWebpackConfig` - the callback function that allows you to edit webpack configs. See more details below


## ModifyWebpackConfig
Expand Down
10 changes: 9 additions & 1 deletion eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
"plugins": [
"json"
],

"rules": {
"no-lonely-if": 2,
"no-nested-ternary": 2,
"max-nested-callbacks": [2, { "max": 5 }],
"constructor-super": 2,
"no-this-before-super": 2,
"prefer-spread": 2,
"prefer-reflect": 2,
"no-warning-comments": [1, { "terms": ["todo", "fixme"], "location": "start" }],
"react/sort-comp": 0,
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"import/no-unresolved": [2, { "ignore": ["ava"] }],
"import/no-extraneous-dependencies": [0]
Expand Down