Skip to content

Commit

Permalink
fix: properly detect missing eslint config file for newer eslint (#138)
Browse files Browse the repository at this point in the history
Fixes #134

Newer eslint puts the message on stderr, and older eslint puts it on stdout, so
just check both.
  • Loading branch information
alangpierce authored Oct 30, 2017
1 parent 89e1cd3 commit 622cf76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"babel-register": "^6.11.6",
"babelrc-rollup": "^3.0.0",
"decaffeinate": "^3.0.0",
"eslint": "^3.18.0",
"eslint": "^4.10.0",
"eslint-plugin-babel": "^4.0.0",
"jscodeshift": "^0.3.30",
"mocha": "^3.0.2",
Expand Down
10 changes: 5 additions & 5 deletions src/modernize/runEslintFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ function makeEslintFixFn(config, {isUpdate}) {
// Ignore the eslint exit code; it gives useful stdout in the same format
// regardless of the exit code. Also keep a 10MB buffer since sometimes
// there can be a LOT of lint failures.
let eslintOutputStr = (await exec(
let [eslintStdout, eslintStderr] = (await exec(
`${config.eslintPath} --fix --format json ${path}; :`,
{maxBuffer: 10000*1024}))[0];
{maxBuffer: 10000*1024}));

let ruleIds;
if (eslintOutputStr.includes("ESLint couldn't find a configuration file")) {
if ((eslintStdout + eslintStderr).includes("ESLint couldn't find a configuration file")) {
messages.push(`Skipping "eslint --fix" on ${path} because there was no eslint config file.`);
ruleIds = [];
} else {
let eslintOutput;
try {
eslintOutput = JSON.parse(eslintOutputStr);
eslintOutput = JSON.parse(eslintStdout);
} catch (e) {
throw new CLIError(`Error while running eslint:\n${eslintOutputStr}`);
throw new CLIError(`Error while running eslint:\n${eslintStdout}\n${eslintStderr}`);
}
ruleIds = eslintOutput[0].messages
.map(message => message.ruleId).filter(ruleId => ruleId);
Expand Down

0 comments on commit 622cf76

Please sign in to comment.