-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Conversation
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution! Especially for making the issue plus writing tests! :) 💯
This looks good to me. I might have a few nitpicks that I'll add later on but I'll merge this soon. If you have allowed edits from maintainers that'd be perfect. Thanks again!
One quick question though, can you make sure this works with the new |
<3 tests :) I'll try to see what I can do tonight. I've allowed edits by the maintainer, but if you add the nitpicks in comments before tonight I can incorporate those as well if you like. |
README.md
Outdated
@@ -45,6 +45,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. | |||
* `failOnError`: Have Webpack's build process die on error. Default: `false` | |||
* `emitErrors`: Display Stylelint errors as actual errors, rather than just warnings. Default: `true` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this list in alphabetical order
test/index.test.js
Outdated
@@ -57,6 +57,65 @@ describe('stylelint-webpack-plugin', function () { | |||
}); | |||
}); | |||
|
|||
it('emits errors as warnings when asked to', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a context
for the emitErrors
tests
(Short update: something came in between, so I probably won't be able to get to this before Friday. Sorry!) |
@JaKXz I found a moment to squeeze this in, two questions though:
I did update the param order in the readme, so that's something :P |
@JaKXz Mind taking a look at my questions above? (Sorry for bugging, I just want to get this in and start using it before I lose motivation myself :P) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping! I was distracted by other projects, my apologies.
-
there is a
lint-dirty-modules.test.js
file so you could start there. What I was thinking was more an integration test so it would probably belong inindex.test.js
and you would do that by having both enabled and verifying the output or the compilation stats [and output verified with testdouble] are correct. -
when I say a
context
, I mean amocha
context
. There are other examples in the test file.context
is just an alias fordescribe
so it helps to organize the different sections of the tests.
I too want to get this in ASAP - then I can release v0.6.1! 😄
lib/run-compilation.js
Outdated
@@ -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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to indicate that these are still errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean to display them in red, then that was my first try. However, it was rather confusing: usually the red means you have to immediately do something, and that the compilation has failed. Thus, if e.g. another, actual error occurred, one might think the style error would have to be fixed as well.
I therefore kept it yellow, since for all intents and purposes, when you've enabled this flag errors are warnings. I'd be willing to change this if you feel red is more appropriate or if you want to prefix it with something, though. (Or feel free to change it yourself.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was thinking was more like a text header or something, but the colours also make sense. Probably a combination to indicate that the errors (in red) are being "ignored" but still reported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, better like this?
This option allows you to log errors as warnings, preventing Webpack dev server from aborting compilation.
1 similar comment
Thanks for the As for the dirty modules test: unfortunately, I did not manage to write a working test. I had a look at To compensate, I did find one potential issue in that test: it says |
lib/run-compilation.js
Outdated
@@ -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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was thinking was more like a text header or something, but the colours also make sense. Probably a combination to indicate that the errors (in red) are being "ignored" but still reported.
test/index.test.js
Outdated
}); | ||
}); | ||
|
||
it('does not emit errors as warnings when not asked to', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say by default
, or even better when emitErrors is not provided
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@Vinnl this looks good so far! Once CI is passing I'll be merging this in and releasing a new version :) |
lib/run-compilation.js
Outdated
compilation.errors.push(chalk.red(options.formatter(errors))); | ||
if (options.emitErrors === false) { | ||
var suppressionWarning = 'Stylelint error, reported as warning because emitErrors is set to false'; | ||
compilation.warnings.push(chalk.yellow(options.formatter(errors + ' - ' + suppressionWarning))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like errors
(the thing passed to style lint's default formatter) is meant to be an array, so you should probably use errors.concat('\n\t - ' + suppressionWarning)
or something to that effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that unexpectedly took me down a rabbit hole :)
Basically, I shouldn't have assumed errors
to be a simple string. It's actually an array of objects containing details about stylelint errors (and warnings).
Of note is that it also contains a property severity
with a value of either warning
or error
. This will in turn cause the formatter to display the warning with either a ⚠ or a ✖ prefixed, respectively, effectively communicating to the user when they were actually errors.
Thus, I've removed the message again and added two tests that ensure that these icons are actually prefixed when appropriate. Hopefully that's OK with you.
And given that I now understood how the stylelint errors are passed through to Webpack, I actually refactored it a bit to unmark files as containing errors, rather than messing with the stats reporter.
Two things to consider:
- I've used
Object.assign
to keep thedowngradeErrors
function pure. This is only supported in Node 4+, so I've added that topackage.json
, if that's OK. - The two new tests are dependent on the formatter marking errors and warnings using the mentioned icons. I'm not too happy with that, but I guess it's reasonable to not expect those to change suddenly.
2 similar comments
Previously, errors would simply be added to Webpack's list of warnings. With this commit, files that include errors actually no longer get marked as such (when `emitErrors` is false). This results in stylelint errors actually being added to the list of warnings, rather than to the list of errors, removing the need to special case them when compiling the compilation stats. Since the `severity` of these errors is still set to `error`, this will still be indicated to the user - it just will no longer abort compilation.
When `emitErrors` is set to false, errors no longer abort the compilation. However, the user might still want to know which warnings are the result of stylelint errors, and which are the results of stylelint warnings. These tests ensure that.
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you've done makes sense, thanks for taking another stab at it. :)
Just have a question that may make things simpler. Let me know what you think.
lib/run-compilation.js
Outdated
if (options.emitErrors === false) { | ||
results = downgradeErrors(results); | ||
} | ||
|
||
warnings = results.filter(function (file) { | ||
return !file.errored && file.warnings && file.warnings.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just check if emitErrors
is disabled here [and then have the errors array return empty]?
this way we don't have to go through results more than twice, and if emitErrors
is false
we'll only have to go through it once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I completely understand your comment: why would we be going through the results more than twice?
As for just leaving the errors array empty: due to the check for !file.errored
when compiling the warnings
array, errors wouldn't be added to the list of warnings either. We could of course expand the check to (!file.errored && options.emitErrors !== false)
, and then another check for options.emitErrors
before filling the errors
array. That would make the code harder to follow I think, but if you prefer that I'd be fine with changing it.
package.json
Outdated
@@ -24,6 +24,9 @@ | |||
"bugs": { | |||
"url": "https://github.com/JaKXz/stylelint-webpack-plugin/issues" | |||
}, | |||
"engines": { | |||
"node": ">=4.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while .travis.yml
does not test against Node < 4, I feel as though I might as well have kept it there since we're not using any language features. Based on my comment above, I think we could keep it that way.
And if we can't for some reason, I'd rather use the object-assign
ponyfill for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allright, I'll remove or polyfill this depending on the resolution above.
@Vinnl I made the changes I was thinking directly on your branch, and it seems like the tests pass just fine. It's probably a good time to make sure all the cases are covered... Anyway, with that change I don't think the |
test/index.test.js
Outdated
}); | ||
}); | ||
|
||
it('does not emit errors as warnings when `emitErrors` is not provided', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test is redundant, it should be covered in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is at the moment. I added it with the idea of atomic unit tests, each testing a specific property of the code. That way, if the expected behaviour of the other unit test changes, this property will still be tested.
@JaKXz Ah, I see what you mean. Yes, that looks fine, and |
So I got a bit carried away and fixed things up [because I'm excited about this feature] :) please do give What would be extremely helpful would be another PR with a more complex fixture... perhaps it's time to introduce snapshot testing for the console output? hmmm. |
Thanks for getting it in, much appreciated :) It does indeed now report the errors as warnings on my actual project. What's interesting, though, is that when I remove Which led me to install 0.6.0, where the same thing happens: even though there's a stylelint error in my CSS, the build is completed successfully. In 0.5.0 (and in 0.4.2, which I was apparently still using), errors do block the build, as expected. |
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
This option allows you to log errors as warnings, preventing
Webpack dev server from aborting compilation.