-
-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Validate property values containing variables #148
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
base: main
Are you sure you want to change the base?
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.
Pull Request Overview
Enables validation of CSS property values that use var()
by tracking custom property definitions and replacing variables before validation.
- Tracks
var()
function calls per declaration and substitutes known custom property values for validation. - Reports errors for unknown variables (
unknownVar
) and invalid substituted values (invalidPropertyValue
). - Adds tests and updates documentation to describe variable validation behavior.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/rules/no-invalid-properties.test.js | Added valid and invalid test cases covering custom property usage |
src/rules/no-invalid-properties.js | Implemented var() tracking, replacement logic, and new error type |
docs/rules/no-invalid-properties.md | Updated limitations section to explain var() validation behavior |
Comments suppressed due to low confidence (2)
src/rules/no-invalid-properties.js:17
- JSDoc tags use '@import' which is non-standard; consider using '@typedef {import("../types.js").CSSRuleDefinition}' or the equivalent JSDoc import syntax for proper type declarations.
* @import { CSSRuleDefinition } from "../types.js"
src/rules/no-invalid-properties.js:143
- [nitpick] Using
var
as a data property key can be confusing since it's a reserved term; consider renaming it tovarName
orcustomProperty
for clarity.
data: { var: name },
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.
Pull Request Overview
This pull request enables validation of CSS property values that include variable references through var(), ensuring that defined custom properties are used correctly.
- Introduces variable tracking and replacement in the no-invalid-properties rule
- Adds comprehensive tests covering various cases with var() usages
- Updates documentation to clarify the behavior when custom properties are defined or missing
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/rules/no-invalid-properties.test.js | Adds test cases for validating both defined and undefined var() usage |
src/rules/no-invalid-properties.js | Implements custom property tracking and replacement logic for var() in declarations |
docs/rules/no-invalid-properties.md | Updates documentation to explain how var() validation is handled |
Comments suppressed due to low confidence (1)
src/rules/no-invalid-properties.js:143
- Instead of returning immediately after encountering an unknown variable, consider reporting all unknown variable errors in the block to provide comprehensive feedback.
context.report({ loc: func.children[0].loc, messageId: "unknownVar", data: { var: name }, });
We have one false positive when we have spaces inside /* eslint css/no-invalid-properties: error */
:root {
--color: red
}
a {
color: var( --color ); // Unknown property 'color' found css/no-invalid-properties
} |
Co-authored-by: Nitin Kumar <[email protected]>
@snitin315 nice find! I'll take a look. |
Prerequisites checklist
What is the purpose of this pull request?
To enable validation of CSS property values containing
var()
. Previously, we just skipped validating these completely. For this to work, the custom property must be defined before it's used, such as:If a custom property is not defined before it's used, a lint violation is reported.
What changes did you make? (Give an overview)
no-invalid-properties
to track custom property values and use them as replacements for the value that is validatedvar()
is validatedRelated Issues
Is there anything you'd like reviewers to focus on?
The highlighted section of code for a violation is different when there is a
var()
vs. when there isn't.var()
(as in HEAD), the individual incorrect value is highlighted. So forborder-top: 1px solid foo
, it'sfoo
that is indicated in the location information.var()
:var()
is the violation, then it's location is highlighted and the replacement value is reported in the message.