-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #857 from nottrobin/max-warnings-option
Reimplement max-warnings as a proper option
- Loading branch information
Showing
13 changed files
with
192 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,90 @@ | ||
'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 error 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}}); | ||
}, | ||
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'); | ||
}, | ||
exceptions.MaxWarningsExceededError | ||
); | ||
|
||
done(); | ||
}); | ||
|
||
it('should raise MaxWarningsExceededError if warnings exceed `max-warnings` of zero', function (done) { | ||
assert.throws( | ||
function () { | ||
var results = lint.lintFiles('tests/sass/indentation/indentation-spaces.scss', {}); // 55 warnings | ||
lint.failOnError(results, {options: {'max-warnings': 0}}); | ||
}, | ||
exceptions.MaxWarningsExceededError | ||
); | ||
assert.throws( | ||
function () { | ||
var results = lint.lintFiles('tests/sass/indentation/indentation-spaces.scss', {}); // 55 warnings | ||
lint.failOnError(results, {}, 'tests/yml/.max-0-warnings.yml'); | ||
}, | ||
exceptions.MaxWarningsExceededError | ||
); | ||
|
||
done(); | ||
}); | ||
|
||
it('should not raise error 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}); // should succceed | ||
lint.failOnError(results, {}, 'yml/.max-100-warnings.yml'); // should succeed | ||
|
||
done(); | ||
}); | ||
|
||
it('should not raise error if no warnings even if `max-warnings` is zero', function (done) { | ||
var results = lint.lintFiles('sass/success.scss', {}); // no warnings | ||
lint.failOnError(results, {'max-warnings': 0}); // should still succceed | ||
lint.failOnError(results, {}, 'yml/.max-0-warnings.yml'); // should still 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,3 @@ | ||
.one { | ||
margin-top: 0; | ||
} |
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: 0 |
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 |