Skip to content

Commit

Permalink
Exit with a different status code when there are results with a "erro…
Browse files Browse the repository at this point in the history
…r" severity
  • Loading branch information
jwilsson committed Feb 10, 2016
1 parent 062950f commit e1d6831
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Vow = require('vow');
var EXIT_CODES = {
OK: 0,
WARNING: 1,
ERROR: 2,
NOINPUT: 66,
SOFTWARE: 70,
CONFIG: 78
Expand Down Expand Up @@ -87,6 +88,7 @@ module.exports = function (program) {

promises = program.args.map(lesshint.checkPath, lesshint);
Vow.all(promises).then(function (results) {
var hasError;
var reporter;

results = [].concat.apply([], results);
Expand All @@ -110,7 +112,15 @@ module.exports = function (program) {
console.error('Could not find reporter "%s".', program.reporter);
}

exitDefer.reject(EXIT_CODES.WARNING);
hasError = results.some(function (result) {
return result.severity === 'error';
});

if (hasError) {
exitDefer.reject(EXIT_CODES.ERROR);
} else {
exitDefer.reject(EXIT_CODES.WARNING);
}
}).fail(function (error) {
console.error('An unkown error occured, please file an issue with this info:');
console.error(error.stack);
Expand Down
7 changes: 7 additions & 0 deletions test/data/config/severity-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"spaceBeforeBrace": {
"enabled": true,
"style": "one_space",
"severity": "error"
}
}
17 changes: 17 additions & 0 deletions test/specs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,21 @@ describe('cli', function () {
expect(status).to.equal(70);
});
});

it('should exit with a error status code when there is at least one result with a severity of "error"', function () {
var result;

sinon.spy(console, 'log');

result = cli({
args: [path.dirname(__dirname) + '/data/files/file.less'],
config: path.dirname(__dirname) + '/data/config/severity-error.json'
});

return result.fail(function (status) {
expect(status).to.equal(2);

console.log.restore();
});
});
});

0 comments on commit e1d6831

Please sign in to comment.