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 positives for color() #6885

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/neat-owls-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `alpha-value-notation` false positives for `color()`
9 changes: 9 additions & 0 deletions lib/rules/alpha-value-notation/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ testRule({
{
code: 'a { color: color(display-p3 0 0 0 / 0.5) }',
},
{
code: 'a { color: color(display-p3 0 0 0) }',
},

// Relative color syntax
{
Expand Down Expand Up @@ -286,6 +289,12 @@ testRule({
{
code: 'a { color: lch(56.29% 19.86 10 / var(--alpha)) }',
},
{
code: 'a { color: color(display-p3 0 0 0) }',
},
{
code: 'a { color: color(display-p3 0 0 0 / 50%) }',
},
],

reject: [
Expand Down
10 changes: 8 additions & 2 deletions lib/rules/alpha-value-notation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,15 @@ function findAlphaInValue(node) {
* @returns {import('postcss-value-parser').Node | undefined}
*/
function findAlphaInFunction(node) {
const args = node.nodes.filter(({ type }) => type === 'word' || type === 'function');
const legacySyntax = node.nodes.some(({ type, value }) => type === 'div' && value === ',');

if (args.length === 4) return args[3];
if (legacySyntax) {
const args = node.nodes.filter(({ type }) => type === 'word' || type === 'function');

if (args.length === 4) return args[3];

return undefined;
}

const slashNodeIndex = node.nodes.findIndex(({ type, value }) => type === 'div' && value === '/');

Expand Down