Skip to content

Commit 119097e

Browse files
authored
Fix declaration-property-value-no-unknown false positives for attr() and if() (#8853)
1 parent 4b9c68b commit 119097e

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stylelint": patch
3+
---
4+
5+
Fixed: `declaration-property-value-no-unknown` false positives for `attr()`, `if()` and custom functions

lib/rules/declaration-property-value-no-unknown/__tests__/index.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ testRule({
9393
code: '@font-face { font-weight: bolder; }',
9494
description: 'ignore descriptors with unknown values',
9595
},
96+
{
97+
code: 'a { color: if(media(all): red;); }',
98+
description: 'ignore csstree parse errors for `if()` function',
99+
},
100+
{
101+
code: 'a { content: attr(data-foo type(<string>)) }',
102+
description: 'ignore csstree parse errors for `attr()` function',
103+
},
96104
{
97105
code: stripIndent`
98106
a { font-weight: bolder; }

lib/rules/declaration-property-value-no-unknown/index.cjs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/declaration-property-value-no-unknown/index.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ const rule = (primary, secondaryOptions) => {
156156

157157
if (containsUnsupportedFunction(cssTreeValueNode)) return;
158158
} catch {
159+
// Ignore parse errors for `attr()`, `if()` and custom functions
160+
// See: https://github.com/stylelint/stylelint/issues/8779
161+
if (/(?:^|[^\w-])(?:attr|if|--[\w-]+)\(/i.test(value)) return;
162+
159163
const index = declarationValueIndex(decl);
160164
const endIndex = index + value.length;
161165

0 commit comments

Comments
 (0)