Skip to content

Commit

Permalink
Fix TypeError for custom properties fallback in length-zero-no-unit (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shirotech committed Aug 10, 2020
1 parent 1e52251 commit 9e1edfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/rules/length-zero-no-unit/__tests__/index.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
},
],
});

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/length-zero-no-unit/index.js
Expand Up @@ -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++) {
Expand Down

0 comments on commit 9e1edfa

Please sign in to comment.