Skip to content

Commit f526b1d

Browse files
authored
fix: Suppress var() validation errors (#45)
refs #40
1 parent 6ebf57e commit f526b1d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

docs/rules/no-invalid-properties.md

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ body {
4242
}
4343
```
4444

45+
### Limitations
46+
47+
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.
48+
4549
## When Not to Use It
4650

4751
If you aren't concerned with invalid properties, then you can safely disable this rule.

src/rules/no-invalid-properties.js

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ export default {
5656
return;
5757
}
5858

59+
/*
60+
* There's no current way to get lexing to work when a
61+
* `var()` is present in a value. Rather than blowing up,
62+
* we'll just ignore it.
63+
*
64+
* https://github.com/csstree/csstree/issues/317
65+
*/
66+
67+
if (error.message.endsWith("var() is not supported")) {
68+
return;
69+
}
70+
5971
// unknown property
6072
context.report({
6173
loc: {

tests/rules/no-invalid-properties.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ruleTester.run("no-invalid-properties", rule, {
3232
"a { color: red; -moz-transition: bar }",
3333
"@font-face { font-weight: 100 400 }",
3434
'@property --foo { syntax: "*"; inherits: false; }',
35+
"a { --my-color: red; color: var(--my-color) }",
3536
],
3637
invalid: [
3738
{

0 commit comments

Comments
 (0)