-
Notifications
You must be signed in to change notification settings - Fork 194
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
feat: Implement pure mode lints for CSS Modules #796
Conversation
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.
Can you add some more tests, the current test only covers the top level but there's other case where it shouldn't error.
Examples:
div .my-class
-> should not error.my-class div
-> should not errordiv.my-class
-> should not error
These are the cases I tried that compile fine with webpack CSS Modules
div.my-class {
color: red;
}
a .my-class {
color: red;
}
.my-class a {
color: red;
}
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 good to me now, thanks for adding the additional tests 💯
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.
Realized this is not documented yet, can you make sure there's documentation added as well, it's in this repo in the website
folder 👍
Could we please also add tests for nesting? should not error: div {
.my-class {
color: red;
}
} div {
.my-class {
span {
color: red;
}
}
} should error: div {
.my-class {
color: red;
}
color: blue
} |
What should happen for cases like |
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 introduced a new selector state flag and I resolved the test case you mentioned.
Co-authored-by: Jan Nicklas <[email protected]>
I think |
We are detecting from selector passer, not AST visitor |
I see - checking only the selector has worked very well for many years this test case works in nextjs using postcss but never will in lightningcss |
I think this should not be allowed: html {
.foo {
/* ... */
}
} because it's easy to start adding declarations to the root However the inverse seems ok: .foo {
div {
/* ... */
}
} |
Updated to implement this in the transform pass rather than in the selector parser, which enables handling of nesting as shown above. |
thanks @kdy1 and @devongovett for all your work! |
Thanks @kdy1 @devongovett @jantimon, great collaboration 😌 |
### What? Update `lightningcss` ### Why? To apply parcel-bundler/lightningcss#796 and parcel-bundler/lightningcss#797 ### How? - Closes PACK-3190 - Closes PACK-3191
Relevant code: https://github.com/css-modules/postcss-modules-local-by-default/blob/5eeb3053bc40061022ebc6f41cd207a405484de1/src/index.js#L518-L520