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 shorthand-property-no-redundant-values false negatives for functions #7657

Merged
merged 7 commits into from Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
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
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;
}
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

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