Skip to content

Commit

Permalink
Fix: incorrect exitCode when eslint is called with --stdin (fixes #6677
Browse files Browse the repository at this point in the history
…) (#6682)

Previously exitCode was set at the end of bin/eslint.js but the callback
executed for --stdin was asynchronous.
The asynchronous callback was setting exitCode after process.exitCode
had already been assigned.

This removes the exitCode variable and just gets each block to set
process.exitCode directly.
  • Loading branch information
shumphrey authored and ilyavolodin committed Jul 15, 2016
1 parent 38639bf commit e8f8c6c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions bin/eslint.js
Expand Up @@ -11,8 +11,7 @@
// Helpers
//------------------------------------------------------------------------------

var exitCode = 0,
useStdIn = (process.argv.indexOf("--stdin") > -1),
var useStdIn = (process.argv.indexOf("--stdin") > -1),
init = (process.argv.indexOf("--init") > -1),
debug = (process.argv.indexOf("--debug") > -1);

Expand Down Expand Up @@ -55,26 +54,24 @@ process.on("uncaughtException", function(err){
if (useStdIn) {
process.stdin.pipe(concat({ encoding: "string" }, function(text) {
try {
exitCode = cli.execute(process.argv, text);
process.exitCode = cli.execute(process.argv, text);
} catch (ex) {
console.error(ex.message);
console.error(ex.stack);
exitCode = 1;
process.exitCode = 1;
}
}));
} else if (init) {
var configInit = require("../lib/config/config-initializer");
configInit.initializeConfig(function(err) {
if (err) {
exitCode = 1;
process.exitCode = 1;
console.error(err.message);
console.error(err.stack);
} else {
exitCode = 0;
process.exitCode = 0;
}
});
} else {
exitCode = cli.execute(process.argv);
process.exitCode = cli.execute(process.argv);
}

process.exitCode = exitCode;

0 comments on commit e8f8c6c

Please sign in to comment.