From 1a92aeb674a22735ea8f5e8fbb5e6f6449f1a246 Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Fri, 30 Jun 2023 10:52:35 +0100 Subject: [PATCH 1/2] Fix selector-id-pattern performance --- .changeset/silly-eagles-grow.md | 5 +++++ lib/rules/selector-id-pattern/index.js | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/silly-eagles-grow.md diff --git a/.changeset/silly-eagles-grow.md b/.changeset/silly-eagles-grow.md new file mode 100644 index 0000000000..89cbe18d03 --- /dev/null +++ b/.changeset/silly-eagles-grow.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `selector-id-pattern` performance diff --git a/lib/rules/selector-id-pattern/index.js b/lib/rules/selector-id-pattern/index.js index e22c6ef74d..941f81332c 100644 --- a/lib/rules/selector-id-pattern/index.js +++ b/lib/rules/selector-id-pattern/index.js @@ -32,6 +32,8 @@ const rule = (primary) => { const normalizedPattern = isString(primary) ? new RegExp(primary) : primary; root.walkRules((ruleNode) => { + if (!ruleNode?.selector.includes('#')) return; + if (!isStandardSyntaxRule(ruleNode)) { return; } From 65dc8bdbdec2cf2391b064033d3b2bfce0954e6e Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Fri, 30 Jun 2023 11:50:45 +0100 Subject: [PATCH 2/2] Refactor to use filter --- lib/rules/selector-id-pattern/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/rules/selector-id-pattern/index.js b/lib/rules/selector-id-pattern/index.js index 941f81332c..c89280a786 100644 --- a/lib/rules/selector-id-pattern/index.js +++ b/lib/rules/selector-id-pattern/index.js @@ -31,9 +31,7 @@ const rule = (primary) => { const normalizedPattern = isString(primary) ? new RegExp(primary) : primary; - root.walkRules((ruleNode) => { - if (!ruleNode?.selector.includes('#')) return; - + root.walkRules(/#/, (ruleNode) => { if (!isStandardSyntaxRule(ruleNode)) { return; }