Skip to content

Commit

Permalink
Merge pull request #937 from DanPurdy/feature/fix-cli-error-throws
Browse files Browse the repository at this point in the history
Fix cli error throws
  • Loading branch information
DanPurdy authored Nov 7, 2016
2 parents 60624c2 + 115cb87 commit 240a148
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
34 changes: 26 additions & 8 deletions bin/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ var program = require('commander'),
lint = require('../index');

var configPath,
configOptions = {};
config,
configOptions = {},
exitCode = 0;

var detectPattern = function (pattern) {
var detects;
var tooManyWarnings = function (detects, userConfig) {
var warningCount = lint.warningCount(detects).count;

detects = lint.lintFiles(pattern, configOptions, configPath);
return warningCount > 0 && warningCount > userConfig.options['max-warnings'];
};

var detectPattern = function (pattern, userConfig) {
var detects = lint.lintFiles(pattern, configOptions, configPath);

if (program.verbose) {
lint.outputResults(detects, configOptions, configPath);
}

lint.failOnError(detects, configOptions, configPath);
if (lint.errorCount(detects).count || tooManyWarnings(detects, userConfig)) {
exitCode = 1;
}

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

program
Expand All @@ -33,7 +45,6 @@ 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
configOptions.files = configOptions.files || {};
configOptions.options = configOptions.options || {};

Expand Down Expand Up @@ -61,11 +72,18 @@ if (program.maxWarnings && program.maxWarnings !== true) {
configOptions.options['max-warnings'] = program.maxWarnings;
}

// load our config here so we only load it once for each file
config = lint.getConfig(configOptions, configPath);

if (program.args.length === 0) {
detectPattern(null);
detectPattern(null, config);
}
else {
program.args.forEach(function (path) {
detectPattern(path);
detectPattern(path, config);
});
}

process.on('exit', function () {
process.exit(exitCode); // eslint-disable-line no-process-exit
});
3 changes: 2 additions & 1 deletion docs/options/max-warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

An error will be thrown if the total number of warnings exceeds the `max-warnings` setting.

> Please note, if you're using this option with the sass-lint CLI and you're specifying the `--no-exit / -q` option too, you will not see an error but an error code of 1 will still be thrown.
## Examples

This can be set as a command-line option:
Expand All @@ -26,4 +28,3 @@ var sassLint = require('sass-lint'),
results = sassLint.lintFiles('sass/**/*.scss', config)
sassLint.failOnError(results, config);
```

0 comments on commit 240a148

Please sign in to comment.