Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hue-degree-notation performance #7012

Merged
merged 3 commits into from Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/empty-starfishes-leave.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `hue-degree-notation` performance
6 changes: 6 additions & 0 deletions lib/rules/hue-degree-notation/index.js
Expand Up @@ -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('|')})\\(`,
jeddy3 marked this conversation as resolved.
Show resolved Hide resolved
'i',
);

/** @type {import('stylelint').Rule} */
const rule = (primary, _secondaryOptions, context) => {
Expand All @@ -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));

Expand Down