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
Fix false positives for JS variables in value-keyword-case #5185
Comments
@jsg2021 Thanks for the report and for using the template. I can reproduce this using the demo. It's likely a problem with the parser stylelint uses to support CSS-in-JS. I've added this issue to #4574, which is a growing list of the problems with the syntax that we need help to fix. Please consider contributing to the parser if you have time.
You can either:
The majority of the built-in rules are applicable to CSS-in-JS object notation, especially the possible errors and feature limiting rules. Even a number of stylistic rules are applicable to strings within object notation, e.g. the following: const Button = styled("button", {
width: "Min( 100VW , .1%)"
} Will be fixed to: const Button = styled("button", {
width: "min(100vw, 0.1%)"
} |
Thanks!
ah, that's a good point. My statement was too broad. I was specifically thinking about identifiers, not string literals. |
I've added this to my code config to prevent js/css lint conflicting fix loops:
|
Did some digging.
At this point, the value in the example is a JS expression, and the |
Thanks for digging.
The CSS-in-JS syntax should probably substitute JS expressions for dummy values in the PostCSS AST. For example: backgroundImage: myBackground ? myBackground : 'url(...)', Becomes: {
"type": "root",
"nodes": [
{
"type": "decl",
"prop": "background-image",
"value": "$dummyvalue"
}
],
} There's experimental work looking into doing this for interpolation in template literals. |
There is a same problem with |
Same here, I've been trying to ignore the There isn't a work around on this? Edit: Thats the pattern if someone is interested: |
Is that the best approach? It just seems like |
I think I’m having the same issue in JSX: const MyComponent = () => {
const minWidth = 42;
return <div style={{ minWidth }}>hello</div>;
} This shows: We already have
(this approach to All works in CLI, but because of a bug in the VSCode extension, the false positive still shows up in the editor. It is possible to set Interestingly, replacing |
Closing as stylistic rules are frozen. The community is welcome to migrate the rule to a plugin and fix this bug. |
stylelint is checking and flagging/fixing javascript as if it were css.
all?
value-keyword-case
in this example.some file named with
.jsx
extensiondemo.jsx:
e.g.
13.11.0
VS code extension and cli... my cli ignores JS files for now. But when I save in vs code, it breaks if I allow its save-action.
no
No validation/fixing on js. CSS in tag template literals is fine to check because that IS css. But JS properties should not be validated.
CSS errors are flagged. (and fixes attempted)
The text was updated successfully, but these errors were encountered: