-
Notifications
You must be signed in to change notification settings - Fork 61
Unable to lint CSS and Styled Components with processor enabled #187
Comments
This was never possible, you will need to use a different Stylelint config that doesn't include our processor in order to lint CSS files |
Dang, that makes it difficult for handling stylelint through vscode. |
Yeah, it sucks. If you want to there might be ways around it, if we could somehow detect whether a file is purely CSS and not JS, such as possibly look at the extension of a file, or use a library that can look at the statics of the code and check whether it parses correctly as CSS and then in that case not apply our processor to it but just pass it through to Stylelint as is. In that case it could probably work. Feel free to work on it and see if you can make it work |
I would love to see this enhancement. Sometimes I just need plain CSS files in addition to styled components. |
If you want to try working on it feel free to ask any questions if you encounter any problems |
I'm not even sure how I would begin. This is pretty complex because even if this processor could be bypassed when a CSS file is detected there is still the matter of getting stylelint to ignore the "stylelint-config-styled-components" extension. I am not sure if that is possible. Right now I have it set up this way: most of my plain CSS is in one directory with its own .stylelintrc file. In the package.json:
The main .stylelintrc file in the src root directory:
And then inside the extras folder:
This works pretty well. Atom-lint will highlight CSS lint errors in the |
Oh that's interesting, yeah changing the rule config is probably not something you can get around without something hacky like that. Either you'd have to just let the rules we disable in the |
stylelint-processor-styled-components を有効にすると stylelint-config-airbnb が無効になるため、public に .stylelintrc.js を新規作成し対応。 styled-components/stylelint-processor-styled-components#187 fix オプションを有効にするとビルドでループが発生するため、package.json の resolution に stylelint-webpack-plugin を定義。 webpack-contrib/stylelint-webpack-plugin#96 stylelint-config-prettier を有効化。
I like the lint script in
(Based on this from SO.) |
Stylelint can be used in VS Code, on both CSS and JS code, by using an npm script (similar to the above) to lint both .css and .js/.jsx files, and then setting up a VS Code task and problem matcher. After setting up (description below), from the VS Code command palette, you'll run "run task > vscode:stylelint", and then you should see output like this: In
Set up your CSS-in-JS stylelint config file (I added a So
And
Then create a Task for VS Code which calls your npm script. In
Note that this problem matcher is almost exactly the same as the built-in VS Code "$eslint-compact" matcher, and differs only in that the severity is lowercase in stylelint ("error" in stylelint vs "Error" from eslint). [If someone knows a simpler way to match, please let me know!] That tells VS Code to match the "compact" stylelint output (
An improvement on this would be making it run as a background task, perhaps with |
Hi, @emilgoldsmith Do you accept a PR for that? |
Yeah sure feel free to submit a PR like that |
Any updates on this?
|
Not as far as I know. Feel free to implement it, shouldn't take long |
Thanks for the sample code solution @brandonkal! |
I added a PR for the @emilgoldsmith I'd be happy if you could review it |
@schoenwaldnils Thank you! v1.8.0 released. |
You must add this to documentation. |
Using
v9.2.1
I am able to lint styled-components once again, however I am not able to lint CSS files while the processor is enabled.The text was updated successfully, but these errors were encountered: