From 3e20a86ed248bf07e248ccff51b3816908e2dc23 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 2 Jul 2023 22:58:12 +0200 Subject: [PATCH 1/4] Fix `selector-type-no-unknown` performance --- lib/rules/selector-type-no-unknown/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/rules/selector-type-no-unknown/index.js b/lib/rules/selector-type-no-unknown/index.js index 6f29bb862c..91d61806c2 100644 --- a/lib/rules/selector-type-no-unknown/index.js +++ b/lib/rules/selector-type-no-unknown/index.js @@ -24,6 +24,8 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/selector-type-no-unknown', }; +const HAS_TAG_NAME_STARTS = /(?:[^.#[:\w-]|^)\w/; + /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { @@ -47,13 +49,15 @@ const rule = (primary, secondaryOptions) => { } root.walkRules((ruleNode) => { - const selector = ruleNode.selector; - const selectors = ruleNode.selectors; - if (!isStandardSyntaxRule(ruleNode)) { return; } + if (!HAS_TAG_NAME_STARTS.test(ruleNode.selector)) return; + + const selector = ruleNode.selector; + const selectors = ruleNode.selectors; + if (selectors.some((s) => isKeyframeSelector(s))) { return; } From 519aeed126d177f323f9a31f1fd8e986b9657ee5 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 2 Jul 2023 23:00:18 +0200 Subject: [PATCH 2/4] rename --- lib/rules/selector-type-no-unknown/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rules/selector-type-no-unknown/index.js b/lib/rules/selector-type-no-unknown/index.js index 91d61806c2..e9846e9d8e 100644 --- a/lib/rules/selector-type-no-unknown/index.js +++ b/lib/rules/selector-type-no-unknown/index.js @@ -24,7 +24,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/selector-type-no-unknown', }; -const HAS_TAG_NAME_STARTS = /(?:[^.#[:\w-]|^)\w/; +const STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:\w-]|^)\w/; /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { @@ -53,7 +53,7 @@ const rule = (primary, secondaryOptions) => { return; } - if (!HAS_TAG_NAME_STARTS.test(ruleNode.selector)) return; + if (!STARTS_A_TAG_NAME_REGEX.test(ruleNode.selector)) return; const selector = ruleNode.selector; const selectors = ruleNode.selectors; From b052cc30b74969514f7421cabe44ba0931675dfe Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Sun, 2 Jul 2023 23:00:38 +0200 Subject: [PATCH 3/4] Create light-dolls-pump.md --- .changeset/light-dolls-pump.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/light-dolls-pump.md diff --git a/.changeset/light-dolls-pump.md b/.changeset/light-dolls-pump.md new file mode 100644 index 0000000000..f421b152cb --- /dev/null +++ b/.changeset/light-dolls-pump.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `selector-type-no-unknown` performance From 1f4a6acd9c68ccf97465a2e47a0684f1df66d371 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Mon, 3 Jul 2023 08:07:52 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- lib/rules/selector-type-no-unknown/index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/rules/selector-type-no-unknown/index.js b/lib/rules/selector-type-no-unknown/index.js index e9846e9d8e..bb43695772 100644 --- a/lib/rules/selector-type-no-unknown/index.js +++ b/lib/rules/selector-type-no-unknown/index.js @@ -49,14 +49,13 @@ const rule = (primary, secondaryOptions) => { } root.walkRules((ruleNode) => { - if (!isStandardSyntaxRule(ruleNode)) { - return; - } + const { selector } = ruleNode; + + if (!STARTS_A_TAG_NAME_REGEX.test(selector)) return; - if (!STARTS_A_TAG_NAME_REGEX.test(ruleNode.selector)) return; + if (!isStandardSyntaxRule(ruleNode)) return; - const selector = ruleNode.selector; - const selectors = ruleNode.selectors; + const { selectors } = ruleNode; if (selectors.some((s) => isKeyframeSelector(s))) { return;