diff --git a/.changeset/hot-doors-jump.md b/.changeset/hot-doors-jump.md new file mode 100644 index 0000000000..e276a67dfb --- /dev/null +++ b/.changeset/hot-doors-jump.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `custom-property-pattern` performance diff --git a/lib/rules/custom-property-pattern/index.js b/lib/rules/custom-property-pattern/index.js index ceef283801..9f8a1dba29 100644 --- a/lib/rules/custom-property-pattern/index.js +++ b/lib/rules/custom-property-pattern/index.js @@ -20,6 +20,8 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/custom-property-pattern', }; +const VAR_FUNC_REGEX = /var\(/i; + /** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { @@ -40,8 +42,8 @@ const rule = (primary) => { */ function check(property) { return ( - !isStandardSyntaxProperty(property) || !isCustomProperty(property) || + !isStandardSyntaxProperty(property) || regexpPattern.test(property.slice(2)) ); } @@ -49,21 +51,23 @@ const rule = (primary) => { root.walkDecls((decl) => { const { prop, value } = decl; - const parsedValue = valueParser(value); + if (VAR_FUNC_REGEX.test(value)) { + const parsedValue = valueParser(value); - parsedValue.walk((node) => { - if (!isValueFunction(node)) return; + parsedValue.walk((node) => { + if (!isValueFunction(node)) return; - if (node.value.toLowerCase() !== 'var') return; + if (node.value.toLowerCase() !== 'var') return; - const { nodes } = node; + const { nodes } = node; - const firstNode = nodes[0]; + const firstNode = nodes[0]; - if (!firstNode || check(firstNode.value)) return; + if (!firstNode || check(firstNode.value)) return; - complain(declarationValueIndex(decl) + firstNode.sourceIndex, firstNode.value, decl); - }); + complain(declarationValueIndex(decl) + firstNode.sourceIndex, firstNode.value, decl); + }); + } if (check(prop)) return;