Skip to content

Commit

Permalink
Exclude var() support
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Apr 26, 2024
1 parent 47ddc79 commit 7ab186d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ testRule({
code: 'a { border-radius: 1px 1px / 1px; }',
description: 'ignore ellipse',
},
{
code: 'a { margin: var(--margin) var(--margin); }',
description: 'ignore variables',
},
{
code: 'a { border-color: #FFFFFF transparent transparent; }',
description: 'ignore upper case value',
Expand Down Expand Up @@ -373,13 +377,6 @@ testRule({
line: 1,
column: 5,
},
{
code: 'a { margin: var(--margin) var(--margin); }',
fixed: 'a { margin: var(--margin); }',
message: messages.rejected('var(--margin) var(--margin)', 'var(--margin)'),
line: 1,
column: 5,
},
{
code: 'a { margin: calc(1px + 1px) calc(1px + 1px); }',
fixed: 'a { margin: calc(1px + 1px); }',
Expand Down
10 changes: 10 additions & 0 deletions lib/rules/shorthand-property-no-redundant-values/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ const rule = (primary, _secondaryOptions, context) => {
break;
}

// `var()` should be ignored. E.g.
//
// --padding: 20px 5px;
// padding: 0 var(--padding) 0;
//
if (typeGuards.isValueFunction(valueNode) && valueNode.value.toLowerCase() === 'var') {
shouldIgnore = true;
break;
}

if (typeGuards.isValueWord(valueNode) || typeGuards.isValueFunction(valueNode)) {
valuesToShorthand.push(valueParser.stringify(valueNode));
}
Expand Down
10 changes: 10 additions & 0 deletions lib/rules/shorthand-property-no-redundant-values/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ const rule = (primary, _secondaryOptions, context) => {
break;
}

// `var()` should be ignored. E.g.
//
// --padding: 20px 5px;
// padding: 0 var(--padding) 0;
//
if (isValueFunction(valueNode) && valueNode.value.toLowerCase() === 'var') {
shouldIgnore = true;
break;
}

if (isValueWord(valueNode) || isValueFunction(valueNode)) {
valuesToShorthand.push(valueParser.stringify(valueNode));
}
Expand Down

0 comments on commit 7ab186d

Please sign in to comment.