-
Notifications
You must be signed in to change notification settings - Fork 58
Add support for CSS validation #47
Comments
Yes! Though perhaps a SCSS validator would be even more useful? |
@mehigh are you aware of a CSS/SCSS validation tool that we should incorporate into our code checks? |
PHP_CodeSniffer can run checks on CSS, though we haven't used them before: https://github.com/squizlabs/PHP_CodeSniffer/tree/master/CodeSniffer/Standards/Squiz/Sniffs/CSS |
@westonruter I'm working on adding PostCSS and Stylelint to WordPress core, hoping to get the last of this sorted next week https://core.trac.wordpress.org/ticket/29792#comment:34 Should also be able to extend to SCSS support now that PostCSS 5.0 is out |
@westonruter I did not use a SCSS validation tool as the compiler is the first line of defence in catching errors. The compilers never generates invalid code. At the slightest hick-up you get very verbose descriptions of the error. This is what I got when I typed Message: That's what I have in the regular gulp processes I built on various projects. (I prefer gulp over grunt due to the more elegant syntax and more clear and concise configuration files). |
I gave http://csslint.net/ a try. And through 270 warnings I got from the stylesheet generated, I noticed 12 valid items which I had included in improving the code base. But it has too big of a signal-to-noise ratio to be a recommendation. |
An SCSS validator would only make sense if we're compiling the SCSS files on the server, as long as this thing is happening locally, it's not a requirement to be added in a pre-commit hook. We could potentially do a 'catch all CSS is valid sort of tool' to be plugged-in regardless on the aspects of how the CSS is built on a per-project basis, but we would only be interested here in errors, and not warnings. As for PostCSS and it becomming a replacement for SASS, what tool I've used with success on many occasions is the AutoPrefixer to which I fed the CSS generated by the pre-processor. Even if PostCSS 5.0 adds SCSS support, I would still maintain the recommendation to use libSass as the go-to solution for CSS compilation (there are threads on the internet talking about it being 3 times as fast than libSass, etc.). I prefer not to go on the 'bleeding edge' and hit compiler-introduced CSS bugs and stick to more stable, tested solutions. Maybe once development starts toning down and PostCSS becomes a more mature solution we can consider switching boats, but now I don't consider it to be the time. |
Stylelint seems to be a wee bit more modern than the CSSLint I just tried earlier. And for things where there shouldn't be a unit defined after a 0, that's the sort of thing which shouldn't require a manual developer interaction to fix upon a lint notices it, instead there are plenty of css optimisers which are better at handling this sort of items when minifying the CSS anyway. So as long as the rule set is adapted to catching actual issues, I think that would be good. |
@ntwb Does stylelint support generating reports in the same formats as ESLint (namely Lines 758 to 776 in e52081e
|
@westonruter Stylelint is just PostCSS plugins. They uses common PostCSS warnings API — @davidtheclark @hudochenkov do we have ESLint compact reporter? Also I think it is nice idea to have same output format (maybe as addition formatter). |
stylelint includes 3 formatters out of the box, A quick search of NPM doesn't reveal a compact formatter, nor a quick GitHub search As @ai notes it should be pretty quick and easy to create a "compact" formatter for us to use: https://stylelint.io/developer-guide/formatters/ I'm happy to take a shot at writing |
I've got this right now based on ESLints compact format: stylelint /Users/netweb/dev/stylelint/stylelint-config-wordpress/__tests__/values-invalid.css: line 6, col 11, error - Unexpected unit (length-zero-no-unit) ESLint:
Can publish as |
Initial release published https://www.npmjs.com/package/stylelint-formatter-compact |
Started PR #239 for adding stylelint integration. I know that it is not correctly handling the |
Something like https://www.npmjs.org/package/grunt-w3c-validation would be a great thing to have.
The text was updated successfully, but these errors were encountered: