-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement max-warnings as a proper option
- Remove custom, slightly hacky code for `max-warnings` from `bin/sass-lint.js` - Tidy up `bin/sass-lint.js` more generally - Add `max-warnings` as an option to be passed to `failOnError`, either through a config file or through passing options directly - Add documentation for the max-warnings option - Create new descriptive exceptions for `failOnError` - MaxWarningsExceededError and SassLintFailureError - Test the functionality of `failOnError`
- Loading branch information
Showing
11 changed files
with
160 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Max warnings | ||
|
||
An error will be thrown if the total number of warnings exceeds the `max-warnings` setting. | ||
|
||
## Examples | ||
|
||
This can be set as a command-line option: | ||
|
||
``` bash | ||
$ sass-lint --max-warnings 50 | ||
``` | ||
|
||
In `.sass-lint.yml`: | ||
|
||
``` yaml | ||
options: | ||
max-warnings: 50 | ||
``` | ||
Or inside a script: | ||
``` javascript | ||
var sassLint = require('sass-lint'), | ||
config = {options: {'max-warnings': 50}}; | ||
|
||
results = sassLint.lintFiles('sass/**/*.scss', config) | ||
sassLint.failOnError(results, config); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
var util = require('util'); | ||
|
||
module.exports = { | ||
SassLintFailureError: function (message) { | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = 'SassLintFailureError'; | ||
this.message = message; | ||
}, | ||
MaxWarningsExceededError: function (message) { | ||
Error.captureStackTrace(this, this.constructor); | ||
this.name = 'MaxWarningsExceededError'; | ||
this.message = message; | ||
} | ||
}; | ||
|
||
util.inherits(module.exports.SassLintFailureError, Error); | ||
util.inherits(module.exports.MaxWarningsExceededError, Error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
var lint = require('../index'), | ||
assert = require('assert'), | ||
exceptions = require('../lib/exceptions'); | ||
|
||
describe('failures', function () { | ||
it('should raise SassLintFailureError if indentation is set to error', function (done) { | ||
assert.throws( | ||
function () { | ||
var results = lint.lintFiles('tests/sass/indentation/indentation-spaces.scss', {rules: {indentation: 2}}); // 14 errors | ||
lint.failOnError(results); // Set indentation to error | ||
}, | ||
exceptions.SassLintFailureError | ||
); | ||
assert.throws( | ||
function () { | ||
var results = lint.lintFiles('tests/sass/indentation/indentation-spaces.scss', {}, 'tests/yml/.indentation-error.yml'); // 14 errors | ||
lint.failOnError(results); // Set indentation to error | ||
}, | ||
exceptions.SassLintFailureError | ||
); | ||
|
||
done(); | ||
}); | ||
|
||
it('should not raise SassLintFailureError if indentation is only set to warn', function (done) { | ||
// These should produce 55 warnings and 0 errors | ||
var directResults = lint.lintFiles('sass/indentation/indentation-spaces.scss', {rules: {indentation: 1}}); | ||
var configResults = lint.lintFiles('sass/indentation/indentation-spaces.scss', {}, 'yml/.indentation-warn.yml'); | ||
lint.failOnError(directResults); | ||
lint.failOnError(configResults); | ||
|
||
done(); | ||
}); | ||
|
||
it('should raise MaxWarningsExceededError if warnings exceed `max-warnings` setting', function (done) { | ||
assert.throws( | ||
function () { | ||
var results = lint.lintFiles('tests/sass/indentation/indentation-spaces.scss', {}); // 55 warnings | ||
lint.failOnError(results, {options: {'max-warnings': 10}}); // Max 10 warnings | ||
}, | ||
exceptions.MaxWarningsExceededError | ||
); | ||
assert.throws( | ||
function () { | ||
var results = lint.lintFiles('tests/sass/indentation/indentation-spaces.scss', {}); // 55 warnings | ||
lint.failOnError(results, {}, 'tests/yml/.max-10-warnings.yml'); // Max 10 warnings | ||
}, | ||
exceptions.MaxWarningsExceededError | ||
); | ||
|
||
done(); | ||
}); | ||
|
||
it('should not raise MaxWarningsExceededError if warnings do not exceed `max-warnings` setting', function (done) { | ||
var results = lint.lintFiles('sass/indentation/indentation-spaces.scss', {}); // 55 warnings | ||
lint.failOnError(results, {'max-warnings': 100}); // Max 100 warnings, should succceed | ||
lint.failOnError(results, {}, 'yml/.max-100-warnings.yml'); // Max 100 warnings, should succeed | ||
|
||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rules: | ||
indentation: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rules: | ||
indentation: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
options: | ||
max-warnings: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
options: | ||
max-warnings: 100 |