Skip to content
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: Suppress var() validation errors #45

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/rules/no-invalid-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ body {
}
```

### Limitations

This rule uses the lexer from [CSSTree](https://github.com/csstree/csstree), which does not support validation of property values that contain variable references (i.e., `var(--bg-color)`). The lexer throws an error when it comes across a variable reference, and rather than displaying that error, this rule ignores it. This unfortunately means that this rule cannot properly validate properties values that contain variable references. We'll continue to work towards a solution for this.

## When Not to Use It

If you aren't concerned with invalid properties, then you can safely disable this rule.
Expand Down
12 changes: 12 additions & 0 deletions src/rules/no-invalid-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ export default {
return;
}

/*
* There's no current way to get lexing to work when a
* `var()` is present in a value. Rather than blowing up,
* we'll just ignore it.
*
* https://github.com/csstree/csstree/issues/317
*/

if (error.message.endsWith("var() is not supported")) {
return;
}

// unknown property
context.report({
loc: {
Expand Down
1 change: 1 addition & 0 deletions tests/rules/no-invalid-properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ruleTester.run("no-invalid-properties", rule, {
"a { color: red; -moz-transition: bar }",
"@font-face { font-weight: 100 400 }",
'@property --foo { syntax: "*"; inherits: false; }',
"a { --my-color: red; color: var(--my-color) }",
],
invalid: [
{
Expand Down
Loading