Skip to content

Commit

Permalink
Fixes webpack-contrib#65: Add emitErrors option
Browse files Browse the repository at this point in the history
This option allows you to log errors as warnings, preventing
Webpack dev server from aborting compilation.
  • Loading branch information
Vinnl committed Feb 1, 2017
1 parent ce6b9ab commit 5da0ed8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
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
6 changes: 5 additions & 1 deletion lib/run-compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ module.exports = function runCompilation (options, compiler, done) {
}

if (errors.length) {
compilation.errors.push(chalk.red(options.formatter(errors)));
if (options.emitErrors === false) {
compilation.warnings.push(chalk.yellow(options.formatter(errors)));
} else {
compilation.errors.push(chalk.red(options.formatter(errors)));
}
errors = [];
}

Expand Down
59 changes: 59 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,65 @@ describe('stylelint-webpack-plugin', 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);
});
});

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

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

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

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

it('works with multiple source files', function () {
var config = {
context: './test/fixtures/multiple-sources',
Expand Down

0 comments on commit 5da0ed8

Please sign in to comment.