Skip to content

Commit

Permalink
Fix custom-property-pattern performance (#7009)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeddy3 committed Jun 30, 2023
1 parent c49290a commit 76a4648
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-doors-jump.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `custom-property-pattern` performance
24 changes: 14 additions & 10 deletions lib/rules/custom-property-pattern/index.js
Expand Up @@ -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) => {
Expand All @@ -40,30 +42,32 @@ const rule = (primary) => {
*/
function check(property) {
return (
!isStandardSyntaxProperty(property) ||
!isCustomProperty(property) ||
!isStandardSyntaxProperty(property) ||
regexpPattern.test(property.slice(2))
);
}

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;

Expand Down

0 comments on commit 76a4648

Please sign in to comment.