Skip to content

Commit

Permalink
Copying ESLint config instead of linking. updating with wf-style rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ccpricenytimes committed Aug 18, 2016
1 parent 54546f8 commit 82ebead
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
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');

This comment has been minimized.

Copy link
@tizmagik

tizmagik Aug 18, 2016

Contributor

You will also need to check for eslintrc and eslint settings in package.json and the other handful of ways to specify eslint settings.

This comment has been minimized.

Copy link
@ccpricenytimes

ccpricenytimes Aug 18, 2016

Author Contributor

I think we should choose one convention to support and only use that. My vote would be for eslint.json or .eslint.rc

thoughts @tizmagik or @delambo

This comment has been minimized.

Copy link
@tizmagik

tizmagik Aug 18, 2016

Contributor

The challenge is for an existing project that specifies eslint settings in package.json for example, if we don't look for that and instead create an eslint.json file for them then suddenly their esint settings are ignored.

If the concern is about the overhead associated with checking all the different ways eslint settings can be configured (I think there's like 4 or 5 ways), then I'd suggest making this step an interactive step where we ask the user if they want an eslint file or not.


// 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();
}
};
10 changes: 5 additions & 5 deletions cli/actions/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ module.exports = (program) => {
// 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');
logger.task('Copied ESLint config from starter-kyt');
}
} else {
// Create a symbolic link from our local eslint
// Copy our local eslint
const esLintPath = path.join(userRootPath, 'node_modules/kyt/eslint.json');
if (shell.ln('-s', esLintPath, linkedPath).code === 0) {
logger.task('Linked esLint config');
if (shell.cp(esLintPath, linkedPath).code === 0) {
logger.task('Copied kyt default ESLint config');
}
}
};
Expand Down Expand Up @@ -197,7 +197,7 @@ 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 {
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

0 comments on commit 82ebead

Please sign in to comment.