From 80fafbee47f69f2e52f92debe57909392d072b94 Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Sat, 6 Feb 2021 09:26:36 +0000 Subject: [PATCH] Fix false negatives for CSS variables in alpha-value-notation --- .../alpha-value-notation/__tests__/index.js | 17 +++++++++++++++++ lib/rules/alpha-value-notation/index.js | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/rules/alpha-value-notation/__tests__/index.js b/lib/rules/alpha-value-notation/__tests__/index.js index adde8ba2f3..cb203676c9 100644 --- a/lib/rules/alpha-value-notation/__tests__/index.js +++ b/lib/rules/alpha-value-notation/__tests__/index.js @@ -46,6 +46,9 @@ testRule({ { code: 'a { color: hsla(var(--hue), var(--sat), var(--sat), var(--alpha)) }', }, + { + code: 'a { color: hsl(var(--hsl) / 0.5) }', + }, { code: 'a { color: lch(56.29% 19.86 10 / var(--alpha)) }', }, @@ -100,6 +103,20 @@ testRule({ line: 1, column: 26, }, + { + code: 'a { color: hsl(var(--hsl) / 50%) }', + fixed: 'a { color: hsl(var(--hsl) / 0.5) }', + message: messages.expected('50%', '0.5'), + line: 1, + column: 29, + }, + { + code: 'a { color: hsl(var(--hsl) / /* comment*/ 50%) }', + fixed: 'a { color: hsl(var(--hsl) / /* comment*/ 0.5) }', + message: messages.expected('50%', '0.5'), + line: 1, + column: 42, + }, { code: stripIndent` a { diff --git a/lib/rules/alpha-value-notation/index.js b/lib/rules/alpha-value-notation/index.js index 7112654525..9244a7359a 100644 --- a/lib/rules/alpha-value-notation/index.js +++ b/lib/rules/alpha-value-notation/index.js @@ -130,6 +130,14 @@ function findAlphaInFunction(node) { if (args.length === 4) return args[3]; + const slashNodeIndex = node.nodes.findIndex(({ type, value }) => type === 'div' && value === '/'); + + if (slashNodeIndex !== -1) { + const nodesAfterSlash = node.nodes.slice(slashNodeIndex + 1, node.nodes.length); + + return nodesAfterSlash.find(({ type }) => type === 'word'); + } + return false; }