diff --git a/lib/rules/custom-property-pattern/__tests__/index.js b/lib/rules/custom-property-pattern/__tests__/index.js index e6bb4861a3..6eaaed257c 100644 --- a/lib/rules/custom-property-pattern/__tests__/index.js +++ b/lib/rules/custom-property-pattern/__tests__/index.js @@ -125,3 +125,18 @@ testRule({ }, ], }); + +testRule({ + ruleName, + customSyntax: 'postcss-scss', + config: [/foo-.+/], + + accept: [ + { + code: 'a { color: var($foo-color); }', + }, + { + code: 'a { color: var(tokens.$bar-color); }', + }, + ], +}); diff --git a/lib/rules/custom-property-pattern/index.js b/lib/rules/custom-property-pattern/index.js index e9bc7f942a..3e90727ba9 100644 --- a/lib/rules/custom-property-pattern/index.js +++ b/lib/rules/custom-property-pattern/index.js @@ -45,7 +45,11 @@ const rule = (primary) => { const { nodes, sourceIndex } = node; - if (regexpPattern.test(nodes[0].value.slice(2))) return; + const { value: firstNodeValue } = nodes[0]; + + if (!isCustomProperty(firstNodeValue)) return; + + if (regexpPattern.test(firstNodeValue.slice(2))) return; complain(declarationValueIndex(decl) + sourceIndex, decl); });