Skip to content

Commit

Permalink
sasstoolsGH-73 Add feature to take max-warnings option into account
Browse files Browse the repository at this point in the history
  • Loading branch information
molsm committed Feb 24, 2019
1 parent 4659cab commit 5d57b82
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ sassLint.format = function (writable) {

sassLint.failOnError = function () {
var filesWithErrors = [];
var filesWithWarnings = [];
var compile = through({objectMode: true}, function (file, encoding, cb) {
if (file.isNull()) {
return cb();
Expand All @@ -99,17 +100,37 @@ sassLint.failOnError = function () {
filesWithErrors.push(file);
}

if (file.sassLint[0].warningCount > 0) {
filesWithWarnings.push(file);
}

this.push(file);
cb();
}, function (cb) {
var errorMessage;
var errorMessage = [],
warningCount,
maxWarningLimit;

if (filesWithErrors.length > 0) {
errorMessage = filesWithErrors.map(function (file) {
return file.sassLint[0].errorCount + ' errors detected in ' + file.relative
}).join('\n');
});
}

if (filesWithWarnings.length > 0 && !isNaN(filesWithWarnings[0].sassConfig.options['max-warning'])) {
maxWarningLimit = filesWithWarnings[0].sassConfig.options['max-warning'];

warningCount = filesWithWarnings.reduce(function (accumulator, file) {
return accumulator + file.sassLint[0].warningCount;
}, 0);

if (warningCount > maxWarningLimit) {
errorMessage.push('Number of warnings (' + warningCount + ') exceeds the allowed maximum of ' + maxWarningLimit)
}
}

this.emit('error', new PluginError(PLUGIN_NAME, errorMessage));
if (errorMessage.length > 0) {
this.emit('error', new PluginError(PLUGIN_NAME, errorMessage.join('\n')));
}

cb();
Expand Down

0 comments on commit 5d57b82

Please sign in to comment.