Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #65: Add emitErrors option #66

Merged
merged 11 commits into from
Feb 20, 2017
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ See [stylelint options](http://stylelint.io/user-guide/node-api/#options) for th

* `configFile`: You can change the config file location. Default: (`undefined`), handled by [stylelint's cosmiconfig module](http://stylelint.io/user-guide/configuration/).
* `context`: String indicating the root of your SCSS files. Default: inherits from webpack config.
* `emitErrors`: Display Stylelint errors as actual errors, rather than just warnings. Default: `true`
* `failOnError`: Have Webpack's build process die on error. Default: `false`
* `files`: Change the glob pattern for finding files. Default: (`['**/*.s?(a|c)ss']`)
* `formatter`: Use a custom formatter to print errors to the console. Default: (`require('stylelint').formatters.string`)
Expand Down
4 changes: 2 additions & 2 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ module.exports = function runCompilation (options, compiler, done) {
.then(function linterSuccess (lint) {
var results = lint.results;

warnings = results.filter(function (file) {
warnings = options.emitErrors === false ? results : results.filter(function (file) {
return !file.errored && file.warnings && file.warnings.length;
});

errors = results.filter(function (file) {
errors = options.emitErrors === false ? [] : results.filter(function (file) {
return file.errored;
});

Expand Down
63 changes: 63 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,48 @@ describe('stylelint-webpack-plugin', function () {
});
});

context('when `emitErrors` is disabled', function () {
it('emits errors as warnings when asked to', function () {
var config = {
context: './test/fixtures/single-error',
entry: './index',
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
emitErrors: false
})
]
};

return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(0);
expect(stats.compilation.warnings).to.have.length(1);
expect(stats.compilation.warnings[0]).to.contain('✖');
});
});

it('still indicates that warnings are warnings to the user, even when emitting errors as warnings too', function () {
var config = {
context: './test/fixtures/rule-warning',
entry: './index',
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
emitErrors: false
})
]
};

return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.warnings[0]).to.contain('⚠');
});
});
});

context('lintDirtyModulesOnly flag is enabled', function () {
it('skips linting on initial run', function () {
var config = {
Expand All @@ -228,5 +270,26 @@ describe('stylelint-webpack-plugin', function () {
expect(stats.compilation.warnings).to.have.length(0);
});
});

it('still skips on initial run with `emitErrors` disabled', function () {
var config = {
context: './test/fixtures/single-error',
entry: './index',
plugins: [
new StyleLintPlugin({
configFile: configFilePath,
quiet: true,
lintDirtyModulesOnly: true,
emitErrors: false
})
]
};

return pack(assign({}, baseConfig, config))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(0);
expect(stats.compilation.warnings).to.have.length(0);
});
});
});
});
2 changes: 1 addition & 1 deletion test/lib/lint-dirty-modules-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('lint-dirty-modules-plugin', function () {
optionsMock = {
configFile: configFilePath,
lintDirtyModulesOnly: true,
fomatter: formatter,
formatter: formatter,
files: [glob]
};
});
Expand Down