Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maxWarnings CLI option #568

Merged
merged 3 commits into from
Apr 17, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ var configPath,
configOptions = {},
exitCode = 0;

var tooManyWarnings = function (detects) {
var warningCount = lint.warningCount(detects).count;

return warningCount > 0 && warningCount > program.maxWarnings;
};

var detectPattern = function (pattern) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var detects;

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

if (lint.errorCount(detects).count) {
if (lint.errorCount(detects).count || tooManyWarnings(detects)) {
exitCode = 1;
}

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


Expand Down
1 change: 1 addition & 0 deletions docs/cli/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Command Line Flag | Description
`-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.
`-h`,`--help` | Outputs usage information for the CLI
`-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)
`--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.
`-o`,`--output [output]` | The path plus file name relative to where Sass Lint is being run from where the output should be written to.
`-q`,`--no-exit` | Prevents the CLI from throwing an error if there is one (useful for development work)
`-s`,`--syntax` | Syntax to evaluate the given file(s) with, either sass or scss. Use with care: overrides filename extension-based syntax detection.
Expand Down
12 changes: 12 additions & 0 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ describe('cli', function () {
});
});

it('should exit with exit code 1 when more warnings than --max-warnings', function (done) {
var command = 'sass-lint -c tests/yml/.color-keyword-errors.yml tests/sass/cli.scss --max-warnings 0';

exec(command, function (err) {
if (err && err.code === 1) {
return done();
}

return done(new Error('Error code not 1'));
});
});

it('should not exit with an error if no config is specified', function (done) {
var command = 'sass-lint tests/sass/cli-clean.scss --verbose --no-exit';

Expand Down