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 false positives for level 4 math functions in length-zero-no-unit #5203

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
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