From 9e1edfac44af9cace9168eb38918674c44bb6782 Mon Sep 17 00:00:00 2001 From: Van Nguyen Date: Tue, 11 Aug 2020 00:21:42 +1000 Subject: [PATCH] Fix TypeError for custom properties fallback in length-zero-no-unit (#4860) --- lib/rules/length-zero-no-unit/__tests__/index.js | 11 +++++++++++ lib/rules/length-zero-no-unit/index.js | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/rules/length-zero-no-unit/__tests__/index.js b/lib/rules/length-zero-no-unit/__tests__/index.js index e0ffd733ad..6efb8e176e 100644 --- a/lib/rules/length-zero-no-unit/__tests__/index.js +++ b/lib/rules/length-zero-no-unit/__tests__/index.js @@ -237,6 +237,10 @@ testRule({ code: 'a { font: normal normal 400 16px /0px cursive; }', description: 'ignore line-height in font declaration', }, + { + code: 'a { font: var(--foo, normal normal 400 16px/0px cursive); }', + description: 'ignore line-height in font declaration within var function', + }, { code: 'a { font: normal normal 400 1.2em cursive; }', description: 'do not fail if no line-height in font declaration', @@ -530,6 +534,13 @@ testRule({ line: 1, column: 30, }, + { + code: 'a { margin: var(--foo, 0px); }', + fixed: 'a { margin: var(--foo, 0); }', + message: messages.rejected, + line: 1, + column: 25, + }, ], }); diff --git a/lib/rules/length-zero-no-unit/index.js b/lib/rules/length-zero-no-unit/index.js index 40acda60a3..6145771b27 100644 --- a/lib/rules/length-zero-no-unit/index.js +++ b/lib/rules/length-zero-no-unit/index.js @@ -40,9 +40,9 @@ function rule(actual, secondary, context) { const ignorableIndexes = new Array(stringValue.length).fill(false); const parsedValue = valueParser(stringValue); - parsedValue.walk((node, nodeIndex) => { + parsedValue.walk((node, nodeIndex, nodes) => { if (decl.prop.toLowerCase() === 'font' && node.type === 'div' && node.value === '/') { - const lineHeightNode = parsedValue.nodes[nodeIndex + 1]; + const lineHeightNode = nodes[nodeIndex + 1]; const lineHeightNodeValue = valueParser.stringify(lineHeightNode); for (let i = 0; i < lineHeightNodeValue.length; i++) {