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;