Skip to content

Commit d24068b

Browse files
committed
Merge pull request #568 from house9/max-warnings
Add maxWarnings CLI option
2 parents 9fa414d + 4cfcc6b commit d24068b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

bin/sass-lint.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ var configPath,
1010
configOptions = {},
1111
exitCode = 0;
1212

13+
var tooManyWarnings = function (detects) {
14+
var warningCount = lint.warningCount(detects).count;
15+
16+
return warningCount > 0 && warningCount > program.maxWarnings;
17+
};
18+
1319
var detectPattern = function (pattern) {
1420
var detects;
1521

@@ -19,7 +25,7 @@ var detectPattern = function (pattern) {
1925
lint.outputResults(detects, configOptions, configPath);
2026
}
2127

22-
if (lint.errorCount(detects).count) {
28+
if (lint.errorCount(detects).count || tooManyWarnings(detects)) {
2329
exitCode = 1;
2430
}
2531

@@ -38,6 +44,7 @@ program
3844
.option('-f, --format [format]', 'pass one of the available eslint formats')
3945
.option('-o, --output [output]', 'the path and filename where you would like output to be written')
4046
.option('-s, --syntax [syntax]', 'syntax to evaluate the file(s) with (either sass or scss)')
47+
.option('--max-warnings [integer]', 'Number of warnings to trigger nonzero exit code')
4148
.parse(process.argv);
4249

4350

docs/cli/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Command Line Flag | Description
1616
`-f`,`--format [format]` | Pass one of the available [Eslint formats](https://github.com/eslint/eslint/tree/master/lib/formatters) to format the output of sass-lint results.
1717
`-h`,`--help` | Outputs usage information for the CLI
1818
`-i`,`--ignore [pattern]` | A pattern that should be ignored from linting. Multiple patterns can be used by separating each pattern by `, `. Patterns should be wrapped in quotes (will be merged with other ignore options)
19+
`--max-warnings [integer]`| Normally, if SassLint runs and finds no errors (only warnings), it will exit with a success exit status. However, if this option is specified and the total warning count is greater than the specified threshold, SassLint will exit with an error status.
1920
`-o`,`--output [output]` | The path plus file name relative to where Sass Lint is being run from where the output should be written to.
2021
`-q`,`--no-exit` | Prevents the CLI from throwing an error if there is one (useful for development work)
2122
`-s`,`--syntax` | Syntax to evaluate the given file(s) with, either sass or scss. Use with care: overrides filename extension-based syntax detection.

tests/cli.js

+12
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ describe('cli', function () {
320320
});
321321
});
322322

323+
it('should exit with exit code 1 when more warnings than --max-warnings', function (done) {
324+
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --max-warnings 0';
325+
326+
exec(command, function (err) {
327+
if (err && err.code === 1) {
328+
return done();
329+
}
330+
331+
return done(new Error('Error code not 1'));
332+
});
333+
});
334+
323335
it('should not exit with an error if no config is specified', function (done) {
324336
var command = 'sass-lint tests/sass/cli-clean.scss --verbose --no-exit';
325337

0 commit comments

Comments
 (0)