Skip to content

Commit a2e5a6d

Browse files
VinnlJaKXz
authored andcommitted
feat: add emitErrors option (#66)
Resolves #65. This option allows you to log errors as warnings, preventing webpack-dev-server from aborting compilation. * tests: fix typo in lint-dirty-modules test
1 parent c222b13 commit a2e5a6d

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ See [stylelint options](http://stylelint.io/user-guide/node-api/#options) for th
4444

4545
* `configFile`: You can change the config file location. Default: (`undefined`), handled by [stylelint's cosmiconfig module](http://stylelint.io/user-guide/configuration/).
4646
* `context`: String indicating the root of your SCSS files. Default: inherits from webpack config.
47+
* `emitErrors`: Display Stylelint errors as actual errors, rather than just warnings. Default: `true`
4748
* `failOnError`: Have Webpack's build process die on error. Default: `false`
4849
* `files`: Change the glob pattern for finding files. Default: (`['**/*.s?(a|c)ss']`)
4950
* `formatter`: Use a custom formatter to print errors to the console. Default: (`require('stylelint').formatters.string`)

lib/run-compilation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ module.exports = function runCompilation (options, compiler, done) {
1919
.then(function linterSuccess (lint) {
2020
var results = lint.results;
2121

22-
warnings = results.filter(function (file) {
22+
warnings = options.emitErrors === false ? results : results.filter(function (file) {
2323
return !file.errored && file.warnings && file.warnings.length;
2424
});
2525

26-
errors = results.filter(function (file) {
26+
errors = options.emitErrors === false ? [] : results.filter(function (file) {
2727
return file.errored;
2828
});
2929

test/index.test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,48 @@ describe('stylelint-webpack-plugin', function () {
208208
});
209209
});
210210

211+
context('when `emitErrors` is disabled', function () {
212+
it('emits errors as warnings when asked to', function () {
213+
var config = {
214+
context: './test/fixtures/single-error',
215+
entry: './index',
216+
plugins: [
217+
new StyleLintPlugin({
218+
configFile: configFilePath,
219+
quiet: true,
220+
emitErrors: false
221+
})
222+
]
223+
};
224+
225+
return pack(assign({}, baseConfig, config))
226+
.then(function (stats) {
227+
expect(stats.compilation.errors).to.have.length(0);
228+
expect(stats.compilation.warnings).to.have.length(1);
229+
expect(stats.compilation.warnings[0]).to.contain('✖');
230+
});
231+
});
232+
233+
it('still indicates that warnings are warnings to the user, even when emitting errors as warnings too', function () {
234+
var config = {
235+
context: './test/fixtures/rule-warning',
236+
entry: './index',
237+
plugins: [
238+
new StyleLintPlugin({
239+
configFile: configFilePath,
240+
quiet: true,
241+
emitErrors: false
242+
})
243+
]
244+
};
245+
246+
return pack(assign({}, baseConfig, config))
247+
.then(function (stats) {
248+
expect(stats.compilation.warnings[0]).to.contain('⚠');
249+
});
250+
});
251+
});
252+
211253
context('lintDirtyModulesOnly flag is enabled', function () {
212254
it('skips linting on initial run', function () {
213255
var config = {
@@ -228,5 +270,26 @@ describe('stylelint-webpack-plugin', function () {
228270
expect(stats.compilation.warnings).to.have.length(0);
229271
});
230272
});
273+
274+
it('still skips on initial run with `emitErrors` disabled', function () {
275+
var config = {
276+
context: './test/fixtures/single-error',
277+
entry: './index',
278+
plugins: [
279+
new StyleLintPlugin({
280+
configFile: configFilePath,
281+
quiet: true,
282+
lintDirtyModulesOnly: true,
283+
emitErrors: false
284+
})
285+
]
286+
};
287+
288+
return pack(assign({}, baseConfig, config))
289+
.then(function (stats) {
290+
expect(stats.compilation.errors).to.have.length(0);
291+
expect(stats.compilation.warnings).to.have.length(0);
292+
});
293+
});
231294
});
232295
});

test/lib/lint-dirty-modules-plugin.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('lint-dirty-modules-plugin', function () {
3232
optionsMock = {
3333
configFile: configFilePath,
3434
lintDirtyModulesOnly: true,
35-
fomatter: formatter,
35+
formatter: formatter,
3636
files: [glob]
3737
};
3838
});

0 commit comments

Comments
 (0)