From 21e7345424924900bb16093de069d297b516f5c3 Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Mon, 3 Jul 2023 08:21:34 +0200 Subject: [PATCH] Fix `selector-type-no-unknown` performance (#7027) Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- .changeset/light-dolls-pump.md | 5 +++++ lib/rules/selector-type-no-unknown/index.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) 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 diff --git a/lib/rules/selector-type-no-unknown/index.js b/lib/rules/selector-type-no-unknown/index.js index 6f29bb862c..bb43695772 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 STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:\w-]|^)\w/; + /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { @@ -47,12 +49,13 @@ const rule = (primary, secondaryOptions) => { } root.walkRules((ruleNode) => { - const selector = ruleNode.selector; - const selectors = ruleNode.selectors; + const { selector } = ruleNode; - if (!isStandardSyntaxRule(ruleNode)) { - return; - } + if (!STARTS_A_TAG_NAME_REGEX.test(selector)) return; + + if (!isStandardSyntaxRule(ruleNode)) return; + + const { selectors } = ruleNode; if (selectors.some((s) => isKeyframeSelector(s))) { return;