From a0ea3ab161c00d7fd04f328c76c89f40f0ff01f4 Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Fri, 30 Jun 2023 10:37:34 +0100 Subject: [PATCH 1/3] Fix hue-degree-notation performance --- .changeset/empty-starfishes-leave.md | 5 +++++ lib/rules/hue-degree-notation/index.js | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/empty-starfishes-leave.md diff --git a/.changeset/empty-starfishes-leave.md b/.changeset/empty-starfishes-leave.md new file mode 100644 index 0000000000..0fae632491 --- /dev/null +++ b/.changeset/empty-starfishes-leave.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `hue-degree-notation` performance diff --git a/lib/rules/hue-degree-notation/index.js b/lib/rules/hue-degree-notation/index.js index 234c41d451..6ef5ee32c7 100644 --- a/lib/rules/hue-degree-notation/index.js +++ b/lib/rules/hue-degree-notation/index.js @@ -24,6 +24,10 @@ const meta = { const HUE_FIRST_ARG_FUNCS = ['hsl', 'hsla', 'hwb']; const HUE_THIRD_ARG_FUNCS = ['lch']; const HUE_FUNCS = new Set([...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS]); +const HAS_HUE_COLOR_FUNC = new RegExp( + `\\b(?:${[...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS].join('|')})\\(`, + 'i', +); /** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { @@ -36,6 +40,8 @@ const rule = (primary, _secondaryOptions, context) => { if (!validOptions) return; root.walkDecls((decl) => { + if (!HAS_HUE_COLOR_FUNC.test(decl.value)) return; + let needsFix = false; const parsedValue = valueParser(getDeclarationValue(decl)); From 7dd3cc517fa9e750ec5b52f540cf39f6ae7d9ba7 Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Fri, 30 Jun 2023 11:51:20 +0100 Subject: [PATCH 2/3] Update lib/rules/hue-degree-notation/index.js Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- lib/rules/hue-degree-notation/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/hue-degree-notation/index.js b/lib/rules/hue-degree-notation/index.js index 6ef5ee32c7..9b078b911e 100644 --- a/lib/rules/hue-degree-notation/index.js +++ b/lib/rules/hue-degree-notation/index.js @@ -25,7 +25,7 @@ const HUE_FIRST_ARG_FUNCS = ['hsl', 'hsla', 'hwb']; const HUE_THIRD_ARG_FUNCS = ['lch']; const HUE_FUNCS = new Set([...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS]); const HAS_HUE_COLOR_FUNC = new RegExp( - `\\b(?:${[...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS].join('|')})\\(`, + `\\b(?:${[...HUE_FUNCS].join('|')})\\(`, 'i', ); From 1d61e9da1c1182d8f41a5138a32da2a87ef709da Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Fri, 30 Jun 2023 11:53:59 +0100 Subject: [PATCH 3/3] Fix lint --- lib/rules/hue-degree-notation/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/rules/hue-degree-notation/index.js b/lib/rules/hue-degree-notation/index.js index 9b078b911e..bad4598f0a 100644 --- a/lib/rules/hue-degree-notation/index.js +++ b/lib/rules/hue-degree-notation/index.js @@ -24,10 +24,7 @@ const meta = { const HUE_FIRST_ARG_FUNCS = ['hsl', 'hsla', 'hwb']; const HUE_THIRD_ARG_FUNCS = ['lch']; const HUE_FUNCS = new Set([...HUE_FIRST_ARG_FUNCS, ...HUE_THIRD_ARG_FUNCS]); -const HAS_HUE_COLOR_FUNC = new RegExp( - `\\b(?:${[...HUE_FUNCS].join('|')})\\(`, - 'i', -); +const HAS_HUE_COLOR_FUNC = new RegExp(`\\b(?:${[...HUE_FUNCS].join('|')})\\(`, 'i'); /** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => {