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 false positives for Less variables and mixins in at-rule-* #3767

Merged
merged 3 commits into from Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions lib/rules/at-rule-semicolon-newline-after/__tests__/index.js
Expand Up @@ -125,3 +125,25 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
syntax: "less",
config: ["always"],
accept: [
{
code: `
.someMixin() { margin: 0; }
span { .someMixin(); }
`,
description: "ignore Less mixin"
},
{
code: `
@myVariable: #f7f8f9;
span { background-color: @myVariable; }
`,
description: "ignore Less variable"
}
]
});
5 changes: 5 additions & 0 deletions lib/rules/at-rule-semicolon-newline-after/index.js
@@ -1,6 +1,7 @@
"use strict";

const hasBlock = require("../../utils/hasBlock");
const isStandardSyntaxAtRule = require("../../utils/isStandardSyntaxAtRule");
const nextNonCommentNode = require("../../utils/nextNonCommentNode");
const rawNodeString = require("../../utils/rawNodeString");
const report = require("../../utils/report");
Expand Down Expand Up @@ -38,6 +39,10 @@ const rule = function(actual, secondary, context) {
return;
}

if (!isStandardSyntaxAtRule(atRule)) {
return;
}

// Allow an end-of-line comment
const nodeToCheck = nextNonCommentNode(nextNode);

Expand Down
24 changes: 24 additions & 0 deletions lib/rules/at-rule-semicolon-space-before/__tests__/index.js
Expand Up @@ -151,3 +151,27 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
syntax: "less",
config: ["always"],
skipBasicChecks: true,

accept: [
{
code: `
.someMixin() { margin: 0; }
span { .someMixin(); }
`,
description: "ignore Less mixin"
},
{
code: `
@myVariable: #f7f8f9;
span { background-color: @myVariable; }
`,
description: "ignore Less variable"
}
]
});
5 changes: 5 additions & 0 deletions lib/rules/at-rule-semicolon-space-before/index.js
@@ -1,6 +1,7 @@
"use strict";

const hasBlock = require("../../utils/hasBlock");
const isStandardSyntaxAtRule = require("../../utils/isStandardSyntaxAtRule");
const rawNodeString = require("../../utils/rawNodeString");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
Expand Down Expand Up @@ -32,6 +33,10 @@ const rule = function(expectation) {
return;
}

if (!isStandardSyntaxAtRule(atRule)) {
return;
}

const nodeString = rawNodeString(atRule);

checker.before({
Expand Down
18 changes: 18 additions & 0 deletions lib/rules/at-rule-whitelist/__tests__/index.js
Expand Up @@ -152,3 +152,21 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
syntax: "less",
config: ["keyframes"],
skipBasicChecks: true,

accept: [
{
code: `
.mixin() { margin: 0; }

span { .mixin(); }
`,
description: "ignore Less mixin which are treated as at-rule"
}
]
});
5 changes: 5 additions & 0 deletions lib/rules/at-rule-whitelist/index.js
@@ -1,6 +1,7 @@
"use strict";

const _ = require("lodash");
const isStandardSyntaxAtRule = require("../../utils/isStandardSyntaxAtRule");
const postcss = require("postcss");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
Expand Down Expand Up @@ -29,6 +30,10 @@ const rule = function(whitelistInput) {
root.walkAtRules(atRule => {
const name = atRule.name;

if (!isStandardSyntaxAtRule(atRule)) {
return;
}

if (
whitelist.indexOf(postcss.vendor.unprefixed(name).toLowerCase()) !== -1
) {
Expand Down