Skip to content
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
3 changes: 1 addition & 2 deletions src/rules/no-invalid-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import { isSyntaxMatchError, isSyntaxReferenceError } from "../util.js";
/**
* Regex to match var() functional notation with optional fallback.
*/
// eslint-disable-next-line regexp/no-super-linear-backtracking -- TODO: fix \s*(.+) to match newline characters
const varFunctionPattern = /var\(\s*(--[^,\s)]+)\s*(?:,\s*(.+))?\)/iu;
const varFunctionPattern = /var\(\s*(--[^,\s)]+)\s*(?:,([\s\S]+))?\)/iu;

/**
* Parses a var() function text and extracts the custom property name and fallback.
Expand Down
40 changes: 40 additions & 0 deletions tests/rules/no-invalid-properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ ruleTester.run("no-invalid-properties", rule, {
":root { --MY-COLOR: red; }\na { color: var(--my-color, blue) }",
":root { --FALLBACK-COLOR: blue; }\na { color: var(--MY-COLOR, var(--FALLBACK-COLOR)) }",
":root { --fallback-color: blue; }\na { color: VAR(--MY-COLOR, VaR(--fallback-color)) }",
"a { color: var(--my-color,\n red) }",
":root { --my-color: red; }\na { color: var(--my-color,\n blue) }",
"a { color: var(--x,\n var(--y,\n blue\n )\n) }",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was invalid before this change (false positive).

"a { color: var(--x,\n red ) }",
":root { --a: var(--b,\n 10px\n); } a { padding: var(--a); }",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was invalid before this change (false positive).

{
code: "a { my-custom-color: red; }",
languageOptions: {
Expand Down Expand Up @@ -975,6 +980,41 @@ ruleTester.run("no-invalid-properties", rule, {
},
],
},
{
code: ":root { --a: var(--b,\n red); }\na { padding-top: var(--a); }",
errors: [
{
messageId: "invalidPropertyValue",
data: {
property: "padding-top",
value: "red",
expected: "<length-percentage [0,∞]>",
},
line: 3,
column: 18,
endLine: 3,
endColumn: 26,
},
],
},
{
code: "a { padding-top: var(--a,\nvar(--b, red\n)\n); }",
options: [{ allowUnknownVariables: true }],
errors: [
{
messageId: "invalidPropertyValue",
data: {
property: "padding-top",
value: "red",
expected: "<length-percentage [0,∞]>",
},
line: 1,
column: 18,
endLine: 4,
endColumn: 2,
},
],
},
Comment on lines +1000 to +1017
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was valid before this change (false negative).

{
code: ":root { --a: var(--b, red); }\na { padding-top: var(--a); }",
errors: [
Expand Down
Loading