From ee7515a2942f08a10d7c5150584f94b9e459c2f1 Mon Sep 17 00:00:00 2001 From: Tomas Hayes Date: Fri, 26 Mar 2021 10:10:19 +0100 Subject: [PATCH] Fix false positives for level 4 math functions in length-zero-no-unit (#5203) --- lib/reference/mathFunctions.js | 2 +- .../length-zero-no-unit/__tests__/index.js | 55 ++++++++++++++++--- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/lib/reference/mathFunctions.js b/lib/reference/mathFunctions.js index 2fe9b67299..e176131a12 100644 --- a/lib/reference/mathFunctions.js +++ b/lib/reference/mathFunctions.js @@ -1,3 +1,3 @@ 'use strict'; -module.exports = ['calc']; +module.exports = ['calc', 'clamp', 'max', 'min']; diff --git a/lib/rules/length-zero-no-unit/__tests__/index.js b/lib/rules/length-zero-no-unit/__tests__/index.js index 6efb8e176e..fc6bcd31c2 100644 --- a/lib/rules/length-zero-no-unit/__tests__/index.js +++ b/lib/rules/length-zero-no-unit/__tests__/index.js @@ -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 */; }', @@ -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: [ { @@ -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: [ { @@ -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) {}',