Skip to content

Commit

Permalink
Fix alpha-value-notation false positives for color() (#6885)
Browse files Browse the repository at this point in the history
* Fix `alpha-value-notation` false positives for `color()`

* cleanup

* Create neat-owls-knock.md
  • Loading branch information
romainmenke committed Jun 2, 2023
1 parent 7206cfc commit 165c827
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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

0 comments on commit 165c827

Please sign in to comment.