Skip to content

Commit

Permalink
Fix false positives for level 4 math functions in length-zero-no-unit (
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyo committed Mar 26, 2021
1 parent 35d486b commit ee7515a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/reference/mathFunctions.js
@@ -1,3 +1,3 @@
'use strict';

module.exports = ['calc'];
module.exports = ['calc', 'clamp', 'max', 'min'];
55 changes: 46 additions & 9 deletions lib/rules/length-zero-no-unit/__tests__/index.js
Expand Up @@ -12,24 +12,48 @@ testRule({
description: 'unitless zero',
},
{
description: 'ignore calc',
code: 'a { padding: calc(0px +\n 0px); }',
description: 'ignore calc',
},
{
description: 'ignore calc. insensitive',
code: 'a { padding: cAlc(0px + 0px); }',
description: 'ignore calc. insensitive',
},
{
description: 'ignore calc. empty calc',
code: 'a { padding: calc(); }',
description: 'ignore calc. empty calc',
},
{
description: 'ignore calc. several `calc`s',
code: 'a { padding: calc(1in + 0in * 2)) 0 calc(0px) 0 }',
description: 'ignore calc. several `calc`s',
},
{
description: 'ignore calc, but not inner functions',
code: 'padding: calc(var(--foo, 0) + 10px) 0',
description: 'ignore calc, but not inner functions',
},
{
code: 'a { right: max(100vw, 0rem)); }',
description: 'ignore max',
},
{
code: 'a { right: calc(max(100vw, 0rem))); }',
description: 'ignore max inside calc',
},
{
code: 'a { right: min(100vw, 0rem)); }',
description: 'ignore min',
},
{
code: 'a { right: calc(min(100vw, 0rem))); }',
description: 'ignore min inside calc',
},
{
code: 'a { right: clamp(50rem, 50vw, 0rem))); }',
description: 'ignore clamp',
},
{
code: 'a { right: calc(clamp(50rem, 50vw, 0rem)))); }',
description: 'ignore clamp inside calc',
},
{
code: 'a { padding: 0 /* 0px */; }',
Expand Down Expand Up @@ -330,8 +354,8 @@ testRule({
},
{
description: 'ignore calc, but not inner functions',
code: 'padding: calc(var(--foo, 0in) + 10px) 0px',
fixed: 'padding: calc(var(--foo, 0) + 10px) 0',
code: 'padding: calc(var(--foo, 0in) + 10px) 0px;',
fixed: 'padding: calc(var(--foo, 0) + 10px) 0;',

warnings: [
{
Expand All @@ -348,8 +372,8 @@ testRule({
},
{
description: 'ignore calc. has another zero units',
code: 'a { padding: calc(1in + 0in * 2)) 0in calc(0px) 0px }',
fixed: 'a { padding: calc(1in + 0in * 2)) 0 calc(0px) 0 }',
code: 'a { padding: calc(1in + 0in * 2)) 0in calc(0px) 0px; }',
fixed: 'a { padding: calc(1in + 0in * 2)) 0 calc(0px) 0; }',

warnings: [
{
Expand All @@ -364,6 +388,19 @@ testRule({
},
],
},
{
description: 'ignore min, max, clamp. has another zero units',
code: 'padding: min(1vw, 0in) max(1vw, 0px) clamp(0em, 1vw, 10px) 0px;',
fixed: 'padding: min(1vw, 0in) max(1vw, 0px) clamp(0em, 1vw, 10px) 0;',

warnings: [
{
message: messages.rejected,
line: 1,
column: 61,
},
],
},
{
code: '@media (min-width: 0px) {}',
fixed: '@media (min-width: 0) {}',
Expand Down

0 comments on commit ee7515a

Please sign in to comment.