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

Ignore less variables (#4200) #4405

Merged
merged 3 commits into from Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
48 changes: 48 additions & 0 deletions lib/rules/length-zero-no-unit/__tests__/index.js
Expand Up @@ -562,3 +562,51 @@ testRule(rule, {
},
],
});

testRule(rule, {
ruleName,
config: [true],
fix: true,
syntax: 'less',
accept: [
{
code: '@variable: 0px;',
description: 'ignore Less variables',
},
{
code: '@detached-ruleset: { line-height: 0px; };',
description: 'ignore Less detached ruleset with line-height',
},
{
code: '@detached-ruleset: { font: normal normal 400 0/0px cursive; };',
description: 'ignore Less detached ruleset with font',
},
],

reject: [
{
code: '@detached-ruleset: { font-size: 0px; };',
fixed: '@detached-ruleset: { font-size: 0; };',

message: messages.rejected,
line: 1,
column: 34,
},
{
code: '@detached-ruleset: { grid-template-columns: 0fr; font-size: 0px; line-height: 0px; };',
fixed: '@detached-ruleset: { grid-template-columns: 0fr; font-size: 0; line-height: 0px; };',

message: messages.rejected,
line: 1,
column: 62,
},
{
code: '@detached-ruleset: { font: normal normal 400 0px/0px cursive; };',
fixed: '@detached-ruleset: { font: normal normal 400 0/0px cursive; };',

message: messages.rejected,
line: 1,
column: 47,
},
],
});
5 changes: 5 additions & 0 deletions lib/rules/length-zero-no-unit/index.js
Expand Up @@ -65,6 +65,11 @@ const rule = function(actual, secondary, context) {
});

root.walkAtRules((atRule) => {
// Ignore Less variables
if (atRule.variable && !hasBlock(atRule)) {
hudochenkov marked this conversation as resolved.
Show resolved Hide resolved
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move this to utils?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable.
Added util function and some tests.


const source = hasBlock(atRule)
? beforeBlockString(atRule, { noRawBefore: true })
: atRule.toString();
Expand Down