Skip to content

Commit

Permalink
Fix selector-type-no-unknown performance (#7027)
Browse files Browse the repository at this point in the history

Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
  • Loading branch information
romainmenke and ybiquitous committed Jul 3, 2023
1 parent cf73360 commit 21e7345
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-dolls-pump.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `selector-type-no-unknown` performance
13 changes: 8 additions & 5 deletions lib/rules/selector-type-no-unknown/index.js
Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down

0 comments on commit 21e7345

Please sign in to comment.