From ef7e77e937763913b9cb7a9d630e21e5d760fbba Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Fri, 30 Jun 2023 12:11:15 +0100 Subject: [PATCH] Fix hue-degree-notation performance (#7012) Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- .changeset/empty-starfishes-leave.md | 5 +++++ lib/rules/hue-degree-notation/index.js | 3 +++ 2 files changed, 8 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..bad4598f0a 100644 --- a/lib/rules/hue-degree-notation/index.js +++ b/lib/rules/hue-degree-notation/index.js @@ -24,6 +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'); /** @type {import('stylelint').Rule} */ const rule = (primary, _secondaryOptions, context) => { @@ -36,6 +37,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));