Skip to content

Commit

Permalink
Adds option to fail or not fail on lint warning (#138)
Browse files Browse the repository at this point in the history
* Adds option to fail on warning, defaults to true to keep current functionality

* Resolve conflicts

* Updates regex, Tests were always passing if compact mode was enabled.

* Updates to use scss_lint 0.49.0

* Updates return status to include status and results
  • Loading branch information
nick11703 authored and Ahmed Nuaman committed Aug 30, 2016
1 parent 2c41c7d commit 3a5a31b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Pull gems from RubyGems
source 'https://rubygems.org'

gem 'scss_lint', '~> 0.48.0'
gem 'scss_lint', '~> 0.49.0'
gem 'scss_lint_reporter_checkstyle', '~> 0.2.0'
gem 'windows-pr' if RUBY_PLATFORM =~ /win32/i || RUBY_PLATFORM =~ /mingw32/i
gem 'win32console' if RUBY_PLATFORM =~ /win32/i || RUBY_PLATFORM =~ /mingw32/i
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ Emits a Grunt event on scss-lint error called `scss-lint-error`.

Emits a Grunt event on scss-lint success called `scss-lint-success`.

#### failOnWarning
- Type: `Boolean`
- Default: `true`

Disable to fail the task only on errors. You can set the severity level for individual linters in your configuration file.

#### force

- Type: `Boolean`
- Default: `false`

Set `force` to `true` to report scss-lint errors but not fail the task.
Set `force` to `true` to report scss-lint warnings and errors but not fail the task. This overrides `failOnWarning`.

#### maxBuffer

Expand Down
13 changes: 9 additions & 4 deletions tasks/lib/scss-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.init = function (grunt) {
make: function (results) {
var output = {},
fileName = '',
matchesRe = /^(.+?\.scss)\:(\d+?)\s(\[\w+?\])\s(.+)/,
matchesRe = /^(.+?\.scss)\:(\d+?)\:(?:\d+?)\s(\[\w+?\])\s(.+)/,
matches;

results = chalk.stripColor(results);
Expand Down Expand Up @@ -197,7 +197,8 @@ exports.init = function (grunt) {
env: env
}, function (err, results, code) {
var message,
rawResults;
rawResults,
failed = true;

if (err && err.code !== 1 && err.code !== 2 && err.code !== 65) {
if (err.code === 127) {
Expand All @@ -209,7 +210,7 @@ exports.init = function (grunt) {
grunt.log.errorlns('and the following message:' + err);
}

return done(false);
return done(false, results);
}

results = results.trim();
Expand All @@ -229,14 +230,18 @@ exports.init = function (grunt) {
} else {
grunt.event.emit('scss-lint-success');
}
failed = false;
} else {
if (!options.emitError) {
grunt.log.writeln(results);
} else {
grunt.event.emit('scss-lint-error', results);
}
if (options.force) {
failed = false;
grunt.log.writeln('scss-lint failed, but was run in force mode');
} else if (err && err.code === 1 && !options.failOnWarning) { // we have just warnings
failed = false;
}
}

Expand All @@ -253,7 +258,7 @@ exports.init = function (grunt) {
grunt.log.writeln('Results have been written to: ' + options.reporterOutput);
}

done(results);
done(failed, results);
});
};

Expand Down
5 changes: 3 additions & 2 deletions tasks/scss-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function (grunt) {
colorizeOutput: false,
compact: false,
force: false,
failOnWarning: true,
maxBuffer: 300 * 1024,
format: null,
require: null
Expand All @@ -49,8 +50,8 @@ module.exports = function (grunt) {
grunt.verbose.writeflags(opts, 'scss-lint options');
grunt.log.writeln('Running scss-lint on ' + target);

scsslint.lint(files, opts, function (results) {
if (opts.force || !results) {
scsslint.lint(files, opts, function (failed, results) {
if (opts.force || !failed) {
done();
} else {
done(false);
Expand Down
20 changes: 10 additions & 10 deletions test/scss-lint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ describe('grunt-scss-lint', function () {
bundleExec: true
});

scsslint.lint(filePass, testOptions, function (results) {
scsslint.lint(filePass, testOptions, function (failed, results) {
childProcessStub.verify();
done();
});
Expand All @@ -283,7 +283,7 @@ describe('grunt-scss-lint', function () {
config: configFile
});

scsslint.lint(filePass, testOptions, function (results) {
scsslint.lint(filePass, testOptions, function (failed, results) {
childProcessStub.verify();
done();
});
Expand All @@ -300,7 +300,7 @@ describe('grunt-scss-lint', function () {
gemVersion: gemVersion
});

scsslint.lint(filePass, testOptions, function (results) {
scsslint.lint(filePass, testOptions, function (failed, results) {
childProcessStub.verify();
done();
});
Expand Down Expand Up @@ -345,8 +345,8 @@ describe('grunt-scss-lint', function () {
var files = '--incorrectlySpecifyingAnOptionAsAFile',
scsslint = require('../tasks/lib/scss-lint').init(grunt);

scsslint.lint(files, defaultOptions, function (results) {
expect(results).to.not.be.ok();
scsslint.lint(files, defaultOptions, function (failed, results) {
expect(failed).to.not.be.ok();
expect(errorlnsStub.getCall(0).args[0]).to.equal('scss-lint failed with error code: 64');
done();
});
Expand All @@ -361,7 +361,7 @@ describe('grunt-scss-lint', function () {
testOptions = _.assign({}, defaultOptions);
testOptions[task] = true;

scsslint.lint(fileFail, testOptions, function (results) {
scsslint.lint(fileFail, testOptions, function (failed, results) {
var styles = chalk.styles;
results = results.split('\n')[0];

Expand All @@ -385,7 +385,7 @@ describe('grunt-scss-lint', function () {
});
testOptions[task] = false;

scsslint.lint(fileFail, testOptions, function (results) {
scsslint.lint(fileFail, testOptions, function (failed, results) {
var styles = chalk.styles;
results = results.split('\n');

Expand All @@ -412,7 +412,7 @@ describe('grunt-scss-lint', function () {
});
testOptions[task] = true;

scsslint.lint(fileFail, testOptions, function (results) {
scsslint.lint(fileFail, testOptions, function (failed, results) {
var styles = chalk.styles;
results = results.split('\n');

Expand All @@ -435,7 +435,7 @@ describe('grunt-scss-lint', function () {

grunt.event.on('scss-lint-error', eventSpy);

scsslint.lint(fileFail, testOptions, function (results) {
scsslint.lint(fileFail, testOptions, function (failed, results) {
results = results.split('\n');
expect(results.length).to.be(5);
expect(eventSpy.calledOnce).to.be.ok();
Expand All @@ -454,7 +454,7 @@ describe('grunt-scss-lint', function () {

grunt.event.on('scss-lint-success', eventSpy);

scsslint.lint(filePass, testOptions, function (results) {
scsslint.lint(filePass, testOptions, function (failed, results) {
expect(eventSpy.called).to.be.ok();
done();
});
Expand Down

0 comments on commit 3a5a31b

Please sign in to comment.