Skip to content

Commit

Permalink
Reimplement max-warnings as a proper option
Browse files Browse the repository at this point in the history
  • Loading branch information
nottrobin committed Aug 31, 2016
1 parent 01eb696 commit e09df5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
47 changes: 14 additions & 33 deletions bin/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ 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) {
var detects;

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

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

if (program.exit) {
lint.failOnError(detects);
lint.failOnError(detects, program.maxWarnings);
}
};

Expand All @@ -47,47 +41,32 @@ program
.option('--max-warnings [integer]', 'Number of warnings to trigger nonzero exit code')
.parse(process.argv);

// Create "options" and "files" dictionaries if they don't exist
if (! configOptions.hasOwnProperty('files')) {
configOptions.files = {}
}
if (! configOptions.hasOwnProperty('options')) {
configOptions.options = {}
}

if (program.config && program.config !== true) {
configPath = program.config;
}

if (program.ignore && program.ignore !== true) {
ignores = program.ignore.split(', ');
if (configOptions.hasOwnProperty('files')) {
configOptions.files.ignore = ignores;
}
else {
configOptions.files = {
'ignore': ignores
};
}
configOptions.files.ignore = program.ignore.split(', ');
}

if (program.syntax && ['sass', 'scss'].indexOf(program.syntax) > -1) {
configOptions.syntax = program.syntax;
}

if (program.format && program.format !== true) {
if (configOptions.hasOwnProperty('options')) {
configOptions.options.formatter = program.format;
}
else {
configOptions.options = {
'formatter': program.format
};
}
configOptions.options.formatter = program.format;
}

if (program.output && program.output !== true) {
if (configOptions.hasOwnProperty('options')) {
configOptions.options['output-file'] = program.output;
}
else {
configOptions.options = {
'output-file': program.output
};
}
configOptions.options['output-file'] = program.output;
}

if (program.args.length === 0) {
Expand All @@ -99,6 +78,8 @@ else {
});
}

debugger;

process.on('exit', function () {
process.exit(exitCode); // eslint-disable-line no-process-exit
});
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,22 @@ sassLint.outputResults = function (results, options, configPath) {
* @param {object} results our results object
* @returns {void}
*/
sassLint.failOnError = function (results) {
var errorCount = this.errorCount(results);
sassLint.failOnError = function (results, maxWarnings) {
var errorCount = this.errorCount(results),
warningCount = this.warningCount(results),
options = this.getConfig().options;

if (options.hasOwnProperty('max-warnings')) {
maxWarnings = typeof maxWarnings == 'undefined' ? options['max-warnings'] : maxWarnings;
}

if (errorCount.count > 0) {
throw new Error(errorCount.count + ' errors were detected in \n- ' + errorCount.files.join('\n- '));
}

if (typeof maxWarnings != 'undefined' && warningCount.count > maxWarnings) {
throw new Error('Number of warnings (' + warningCount.count + ') exceeds the allowed maximum of ' + maxWarnings + '.\n');
}
};

module.exports = sassLint;

0 comments on commit e09df5e

Please sign in to comment.