From 5d57b8211e24adbf2e8dff435801ebe08a27cff0 Mon Sep 17 00:00:00 2001 From: Maris Mols Date: Sun, 24 Feb 2019 21:45:09 +0200 Subject: [PATCH 1/2] GH-73 Add feature to take max-warnings option into account --- index.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7b90123..efff041 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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(); From c12ac2a63d410df901ff83f09288497c31a13884 Mon Sep 17 00:00:00 2001 From: Maris Mols Date: Sun, 24 Feb 2019 21:48:44 +0200 Subject: [PATCH 2/2] GH-73 Misstype corrections --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index efff041..496d78e 100644 --- a/index.js +++ b/index.js @@ -117,8 +117,8 @@ sassLint.failOnError = function () { }); } - if (filesWithWarnings.length > 0 && !isNaN(filesWithWarnings[0].sassConfig.options['max-warning'])) { - maxWarningLimit = filesWithWarnings[0].sassConfig.options['max-warning']; + if (filesWithWarnings.length > 0 && !isNaN(filesWithWarnings[0].sassConfig.options['max-warnings'])) { + maxWarningLimit = filesWithWarnings[0].sassConfig.options['max-warnings']; warningCount = filesWithWarnings.reduce(function (accumulator, file) { return accumulator + file.sassLint[0].warningCount;