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 alpha-value-notation false negatives for oklab(), oklch(), and color() #6844

Merged
Show file tree
Hide file tree
Changes from all commits
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/healthy-planets-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `alpha-value-notation` false negatives for `oklab()`, `oklch()`, and `color()`
61 changes: 61 additions & 0 deletions lib/rules/alpha-value-notation/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,44 @@ testRule({
{
code: 'a { color: lch(56.29% 19.86 10 / var(--alpha)) }',
},
{
code: 'a { color: oklch(56.29% 19.86 10 / var(--alpha)) }',
},
{
code: 'a { color: rgba(0, 0, 0, 0.5/*comment*/) }',
},
{
code: 'a { color: rgb(0 0 0 / /*comment*/0.5) }',
},
{
code: 'a { color: color(display-p3 0 0 0 / 0.5) }',
},

// Relative color syntax
{
code: 'a { color: rgb(from blue 0 0 0 / 0.5) }',
},
{
code: 'a { color: hsl(from blue 198deg 28% 50% / .50) }',
},
{
code: 'a { color: RGB(from blue 0 0 0 / 0.5) }',
},
{
code: 'a { color: hsl(from blue var(--hsl) / 0.5) }',
},
{
code: 'a { color: lch(from rgb(0 0 0) 56.29% 19.86 10 / var(--alpha)) }',
},
{
code: 'a { color: oklch(from #fff 56.29% 19.86 10 / var(--alpha)) }',
},
{
code: 'a { color: rgb(from blue 0 0 0 / /*comment*/0.5) }',
},
{
code: 'a { color: color(from blue display-p3 0 0 0 / 0.5) }',
},
],

reject: [
Expand Down Expand Up @@ -198,6 +230,35 @@ testRule({
endColumn: 18,
description: 'properly deals with floating-point conversions',
},
{
code: 'a { color: rgb(from rgb(127 127 127 / 25%) 0 0 0 / 50%) }',
fixed: 'a { color: rgb(from rgb(127 127 127 / 0.25) 0 0 0 / 0.5) }',
warnings: [
{
message: messages.expected('50%', '0.5'),
line: 1,
column: 52,
endLine: 1,
endColumn: 55,
},
{
message: messages.expected('25%', '0.25'),
line: 1,
column: 39,
endLine: 1,
endColumn: 42,
},
],
},
{
code: 'a { color: color(display-p3 0 0 0 / 50%) }',
fixed: 'a { color: color(display-p3 0 0 0 / 0.5) }',
message: messages.expected('50%', '0.5'),
line: 1,
column: 37,
endLine: 1,
endColumn: 40,
},
],
});

Expand Down
13 changes: 12 additions & 1 deletion lib/rules/alpha-value-notation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ const ALPHA_PROPS = new Set([
'stop-opacity',
'stroke-opacity',
]);
const ALPHA_FUNCS = new Set(['hsl', 'hsla', 'hwb', 'lab', 'lch', 'rgb', 'rgba']);
const ALPHA_FUNCS = new Set([
'color',
'hsl',
'hsla',
'hwb',
'lab',
'lch',
'oklab',
'oklch',
'rgb',
'rgba',
]);

/** @type {import('stylelint').Rule} */
const rule = (primary, secondaryOptions, context) => {
Expand Down