From 9f23cb24f29de2a11ff071f70908ac2a5ca9955a Mon Sep 17 00:00:00 2001 From: Brian White Date: Wed, 27 Apr 2016 01:12:56 -0400 Subject: [PATCH] tools: fix exit code when linting from CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this, if there were lint errors reported by `make jslint-ci`, the process would still exit with an exit code of zero. This commit fixes that to align with `make jslint` (exit with non-zero on lint errors). PR-URL: https://github.com/nodejs/node/pull/6412 Reviewed-By: Johan Bergström Reviewed-By: Phillip Johnsen Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell Reviewed-By: Rich Trott --- tools/jslint.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/jslint.js b/tools/jslint.js index 754ac1a98ca338..64193f15a7c343 100644 --- a/tools/jslint.js +++ b/tools/jslint.js @@ -125,23 +125,28 @@ if (cluster.isMaster) { sendWork(worker); }); - process.on('exit', function() { + process.on('exit', function(code) { if (showProgress) { curPath = 'Done'; printProgress(); outFn('\r\n'); } - process.exit(failures ? 1 : 0); + if (code === 0) + process.exit(failures ? 1 : 0); }); for (i = 0; i < numCPUs; ++i) - cluster.fork().on('message', onWorkerMessage); + cluster.fork().on('message', onWorkerMessage).on('exit', onWorkerExit); function onWorkerMessage(results) { if (typeof results !== 'number') { // The worker sent us results that are not all successes - if (!workerConfig.sendAll) + if (workerConfig.sendAll) { + failures += results.errorCount; + results = results.results; + } else { failures += results.length; + } outFn(formatter(results) + '\r\n'); printProgress(); } else { @@ -151,6 +156,11 @@ if (cluster.isMaster) { sendWork(this); } + function onWorkerExit(code, signal) { + if (code !== 0 || signal) + process.exit(2); + } + function sendWork(worker) { if (!files || !files.length) { // We either just started or we have no more files to lint for the current @@ -245,7 +255,7 @@ if (cluster.isMaster) { } } } - process.send(results); + process.send({ results: results, errorCount: report.errorCount }); } else if (report.errorCount === 0) { // No errors, return number of successful lint operations process.send(files.length);