From 5488de4507ba321506d477efd1ff7a4f9e22853e Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Tue, 4 Jul 2023 13:16:00 +0200 Subject: [PATCH 1/3] Fix `selector-type-case` performance --- lib/rules/selector-type-case/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/rules/selector-type-case/index.js b/lib/rules/selector-type-case/index.js index c2fae483d6..38bbb32658 100644 --- a/lib/rules/selector-type-case/index.js +++ b/lib/rules/selector-type-case/index.js @@ -22,6 +22,10 @@ const meta = { fixable: true, }; +const STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:\w-]|^)\w/; +const ANY_UPPER_CASE_REGEX = /[A-Z]/; +const ANY_LOWER_CASE_REGEX = /[a-z]/; + /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { @@ -48,11 +52,16 @@ const rule = (primary, secondaryOptions, context) => { root.walkRules((ruleNode) => { let hasComments = ruleNode.raws.selector && ruleNode.raws.selector.raw; const selector = hasComments ? hasComments : ruleNode.selector; - const selectors = ruleNode.selectors; - if (!isStandardSyntaxRule(ruleNode)) { - return; - } + if (!STARTS_A_TAG_NAME_REGEX.test(selector)) return; + + if (primary === 'lower' && !ANY_UPPER_CASE_REGEX.test(selector)) return; + + if (primary === 'upper' && !ANY_LOWER_CASE_REGEX.test(selector)) return; + + if (!isStandardSyntaxRule(ruleNode)) return; + + const { selectors } = ruleNode; if (selectors.some((s) => isKeyframeSelector(s))) { return; From 00019bfac7aecf26f52966d024a00ad829844d28 Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Tue, 4 Jul 2023 13:19:48 +0200 Subject: [PATCH 2/3] Create friendly-candles-deny.md --- .changeset/friendly-candles-deny.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/friendly-candles-deny.md diff --git a/.changeset/friendly-candles-deny.md b/.changeset/friendly-candles-deny.md new file mode 100644 index 0000000000..60973810d9 --- /dev/null +++ b/.changeset/friendly-candles-deny.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `selector-type-case` performance From 185cdeadacf49963d9a58a791355334248126e44 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Tue, 4 Jul 2023 14:21:07 +0200 Subject: [PATCH 3/3] update STARTS_A_TAG_NAME_REGEX Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- lib/rules/selector-type-case/index.js | 2 +- lib/rules/selector-type-no-unknown/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rules/selector-type-case/index.js b/lib/rules/selector-type-case/index.js index 38bbb32658..58aa4c7e78 100644 --- a/lib/rules/selector-type-case/index.js +++ b/lib/rules/selector-type-case/index.js @@ -22,7 +22,7 @@ const meta = { fixable: true, }; -const STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:\w-]|^)\w/; +const STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:a-zA-Z-]|^)[a-zA-Z]/; const ANY_UPPER_CASE_REGEX = /[A-Z]/; const ANY_LOWER_CASE_REGEX = /[a-z]/; diff --git a/lib/rules/selector-type-no-unknown/index.js b/lib/rules/selector-type-no-unknown/index.js index bb43695772..aa157cdde5 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 STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:\w-]|^)\w/; +const STARTS_A_TAG_NAME_REGEX = /(?:[^.#[:a-zA-Z-]|^)[a-zA-Z]/; /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => {