fix: var() with fallback value in no-invalid-properties#184
fix: var() with fallback value in no-invalid-properties#184fasttime merged 4 commits intoeslint:mainfrom
no-invalid-properties#184Conversation
| ":root { --my-color: red; }\na { color: var( --my-color ) }", | ||
| ":root { --my-color: red;\n.foo { color: var(--my-color) }\n}", | ||
| ".fluidHeading {font-size: clamp(2.1rem, calc(7.2vw - 0.2rem), 2.5rem);}", | ||
| "a { color: var(--my-color, red) }", |
There was a problem hiding this comment.
Can you add some invalid tests that use fallbacks with incorrect or missing values? Based on the code changes in this PR, I think the error locations will be off.
There was a problem hiding this comment.
Seems you are right, I think it still needs some work, like multiple var in the property and this, so marking it as draft for now. Thanks!
There was a problem hiding this comment.
Have updated the code to fix this and added some tests as well?
nzakas
left a comment
There was a problem hiding this comment.
LGTM, nice job. Would like another review before merging.
|
@Tanujkanti4441 There are few ci failures, can you please check once? |
|
The failures have already been fixed on |
src/rules/no-invalid-properties.js
Outdated
| if ( | ||
| child.children[2].value | ||
| .trim() | ||
| .startsWith("var") | ||
| ) { | ||
| const fallbackVarList = | ||
| getVarFallbackList( | ||
| child.children[2].value.trim(), | ||
| ); |
There was a problem hiding this comment.
If think this should just check if the fallback list is empty, otherwise any value staring with var would be treated as a variable.
| if ( | |
| child.children[2].value | |
| .trim() | |
| .startsWith("var") | |
| ) { | |
| const fallbackVarList = | |
| getVarFallbackList( | |
| child.children[2].value.trim(), | |
| ); | |
| const fallbackVarList = | |
| getVarFallbackList( | |
| child.children[2].value.trim(), | |
| ); | |
| if (fallbackVarList.length > 0) { |
Prerequisites checklist
What is the purpose of this pull request?
To fix the lining errors while using
var()with fallback values.What changes did you make? (Give an overview)
Added a function to remove fallbacks when the variable value is present and a function to get a list of fallback values to use it, when there is no reference present of the variable.
So these cases are the valid:
Related Issues
fixes #180
Is there anything you'd like reviewers to focus on?