Skip to content

Commit

Permalink
Fix false positives for functions inside of math functions in length-…
Browse files Browse the repository at this point in the history
…zero-no-unit rule (#5245)
  • Loading branch information
doing-art committed Apr 20, 2021
1 parent 3be03b9 commit 44c28c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/rules/length-zero-no-unit/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ testRule({
description: 'ignore calc. several `calc`s',
},
{
code: 'padding: calc(var(--foo, 0) + 10px) 0',
description: 'ignore calc, but not inner functions',
code: 'padding: calc(var(--foo, 0px) + 10px) 0',
description: 'ignore calc, and inner functions',
},
{
code: 'padding: max(10px, var(--foo, 0px)) 0',
description: 'ignore max, and inner functions',
},
{
code: 'a { right: max(100vw, 0rem)); }',
Expand Down Expand Up @@ -353,16 +357,11 @@ testRule({
column: 27,
},
{
description: 'ignore calc, but not inner functions',
description: 'ignore calc, and inner functions',
code: 'padding: calc(var(--foo, 0in) + 10px) 0px;',
fixed: 'padding: calc(var(--foo, 0) + 10px) 0;',
fixed: 'padding: calc(var(--foo, 0in) + 10px) 0;',

warnings: [
{
message: messages.rejected,
line: 1,
column: 27,
},
{
message: messages.rejected,
line: 1,
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/length-zero-no-unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function rule(actual, secondary, context) {
for (let i = 0; i < nodeValue.length; i++) {
ignorableIndexes[node.sourceIndex + i] = ignoreFlag;
}

if (isMathFunction) {
return false;
}
});

check(stringValue, decl, ignorableIndexes);
Expand Down

0 comments on commit 44c28c6

Please sign in to comment.