-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Add stylelint #1216
Add stylelint #1216
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Or you could use a Sass linter for both SASS and SCSS syntax! |
stylelint also supports CSS-like syntaxes like SCSS, SugarSS and Less. This is however not relevant for The |
webpack-contrib/stylelint-webpack-plugin#43 has been merged and released as |
packages/react-scripts/package.json
Outdated
@@ -60,6 +61,9 @@ | |||
"recursive-readdir": "2.1.0", | |||
"strip-ansi": "3.0.1", | |||
"style-loader": "0.13.1", | |||
"stylelint": "7.6.0", | |||
"stylelint-config-standard": "15.0.0", | |||
"stylelint-webpack-plugin": "0.4.1", |
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.
@karlhorky I recommend another update here to capture our fixes from this morning (v0.4.2
).
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!
Can you provide some details about node_modules disk size before and after this change please? Also, would this work well for people compiling Sass/Less into CSS, and importing the compiled CSS? Does this plugin work well with Webpack 2? |
9bff79c
to
afbb7f7
Compare
109M node_modules # before
122M node_modules # after
It could lint the original source Sass/Less if I changed the file extensions that are matched by the plugin. I however only enable linting of source files (disabling the linting of any built CSS files) because the built output will be optimized and is thus not a good candidate for linting.
I tested this with a simple application and the plugin works. As for working well, I haven't tested extensively yet - maybe @JaKXz can offer some insight here? |
I've modified the Edit: This appears to be resolved in |
The plugin is actively tested against webpack 2 as of webpack-contrib/stylelint-webpack-plugin#46, so I have confidence in the logic against webpack's compiler [from v0.5.0 on]. |
The scenario I meant is when people compile Sass to CSS but keep it in |
Ah yeah, that would also be supported by changing the file extensions. |
configFile: path.join(__dirname, '../.stylelintrc'), | ||
// @remove-on-eject-end | ||
context: paths.appSrc, | ||
files: ['**/*.css'], |
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.
one thing to consider is that stylelint
can handle .sass
/.scss
files, and the default glob for stylelint-webpack-plugin supports both so you could drop this line.
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.
Ah, nice idea. If @gaearon agrees we want to go this direction, I will make this change.
Is this PR still active?, will it be merged? |
If there's any interest I can rebase and fix conflicts (and upgrade to webpack 2 if necessary). |
There is much interest :) (and to the upgrade to webpack 2 too) |
Handling |
@karlhorky please upgrade to webpack 2 |
Is this pr active? |
Ok, I'll get to this in the next day or so. |
I'd also like to better understand the performance implications of this. If the project has e.g. 500 300-line CSS files, how much does this plugin affect the development and production build times? People already complain about the builds being super slow so I'm not really sure we have the capacity to add any more build-time work. |
727f487
to
43bbaf0
Compare
Perhaps this should be opt-in like some others in #3815? I think the FYI v0.10.1 of the plugin was released recently as well as stylelint v8. |
This seems a bit trickier. We won't make those opt-in by some configuration flag. Instead if you import |
I think the intention here is to have stylelint errors side by side with eslint errors in the build, and assuming CRA works with the better errors webpack plugin that should be achievable :) but I understand your point, I agree it's much harder to pinpoint exactly what the user would want from the outset, and that could change with a lot more volatility. |
Retagging as 2.x because I don't think this should block the 2.0 release. If it slows down our already slow builds I don't think we can do this (but you can always use it separately in your IDE etc). |
2f0a743
to
3290445
Compare
Yes, you can use stylelint in your IDE, but since the errors do not appear in the build output (like eslint), you won't be able to implement a check-in policy that prevents style-violating CSS from being pushed in. :) -Caghan |
I'd prefer Prettier |
rules: { | ||
'at-rule-no-unknown': true, | ||
'color-no-invalid-hex': true, | ||
'declaration-block-no-duplicate-properties': 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.
Wouldn't be better to use declaration-block-no-duplicate-properties with ignore: ["consecutive-duplicates"]
?
Moreover, is this rule blocks the pattern of (Added example)?
margin: 1rem;
margin-bottom: 2rem;
If we have ESLint for JS, we definitely should have Stylelint for CSS. |
Hi there! First of all, thanks to all the contributors for this awesome project. Having all the tools, configuration and setup in one place helps tons.
create-react-app
doesn't have any CSS linting yet. I noticed that there was tentative agreement for further consideration in #636 (comment), so I decided to open a PR for this, since I need it for a project anyway.I've included the standard config because I don't have a full opinionated
stylelint
config yet, but this can of course be changed.Note: This depends on my fork of @vieron's stylelint webpack plugin, because the errors were not displaying correctly using watch mode in CRA. I've opened a pull request on the plugin here: webpack-contrib/stylelint-webpack-plugin#43Edit: Pull request has been merged!