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

fix: stylelint to webpack error output #104

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: stylelint to webpack error output
crash7 committed Jun 24, 2017
commit 060c982ecfe0bfd0ba74e991da87e970dd115ec0
5 changes: 2 additions & 3 deletions lib/run-compilation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var chalk = require('chalk');
var R = require('ramda');
var linter = require('./linter');
var errorMessage = require('./constants').errorMessage;
@@ -41,12 +40,12 @@ module.exports = function runCompilation (options, compiler, done) {

compiler.plugin('after-emit', function afterEmit (compilation, callback) {
if (warnings.length) {
compilation.warnings.push(chalk.yellow(options.formatter(warnings)));
compilation.warnings.push(new Error(options.formatter(warnings)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should warnings really be wrapped in Error objects too? Does this break builds if you only have warnings, but not errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't break anything, the Error wrapper is because webpack is expecting the warnings/errors to be instance of Error in order to display them in the compilation errors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, good to know. And this behaviour is the same across v1, v2, and v3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check v1, so far I tested v2 and v3.

warnings = [];
}

if (errors.length) {
compilation.errors.push(chalk.red(options.formatter(errors)));
compilation.errors.push(new Error(options.formatter(errors)));
errors = [];
}

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@
},
"dependencies": {
"arrify": "^1.0.1",
"chalk": "^1.1.3",
"minimatch": "^3.0.3",
"object-assign": "^4.1.0",
"ramda": "^0.24.1",
11 changes: 7 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -33,8 +33,9 @@ describe('stylelint-webpack-plugin', function () {
return pack(assign({}, baseConfig, { context: path.resolve('./test/fixtures/multiple-sources') }))
.then(function (stats) {
expect(stats.compilation.errors).to.have.length(1);
expect(stats.compilation.errors[0]).to.contain('test/fixtures/multiple-sources/_second.scss');
expect(stats.compilation.errors[0]).to.contain('test/fixtures/multiple-sources/test.scss');
expect(stats.compilation.errors[0]).to.be.an.instanceof(Error);
expect(stats.compilation.errors[0].message).to.contain('test/fixtures/multiple-sources/_second.scss');
expect(stats.compilation.errors[0].message).to.contain('test/fixtures/multiple-sources/test.scss');
});
});

@@ -206,7 +207,8 @@ describe('stylelint-webpack-plugin', function () {
.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('✖');
expect(stats.compilation.warnings[0]).to.be.an.instanceof(Error);
expect(stats.compilation.warnings[0].message).to.contain('✖');
});
});

@@ -215,7 +217,8 @@ describe('stylelint-webpack-plugin', function () {
.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('⚠');
expect(stats.compilation.warnings[0]).to.be.an.instanceof(Error);
expect(stats.compilation.warnings[0].message).to.contain('⚠');
});
});
});