Skip to content

Commit

Permalink
Fix false positives for dollar variables in function-linear-gradient-…
Browse files Browse the repository at this point in the history
…no-nonstandard-direction (#4027)
  • Loading branch information
ccabrales authored and jeddy3 committed Apr 15, 2019
1 parent af2664f commit 68cd18f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Expand Up @@ -266,3 +266,34 @@ testRule(rule, {
}
]
});

// SCSS tests
testRule(rule, {
ruleName,
config: [true],
syntax: "scss",

accept: [
{
code:
".foo { background: linear-gradient($purple-top, $purple-bottom); }",
description: "scss: ignore variable names"
},
{
code:
".foo { background: linear-gradient( $purple-top, $purple-bottom); }"
},
{
code: ".foo { background: linear-gradient($to-top, $purple-bottom); }"
}
],

reject: [
{
code: ".foo { background: linear-gradient(top, $purple-bottom); }",
message: messages.rejected,
line: 1,
column: 36
}
]
});
Expand Up @@ -2,6 +2,7 @@

const declarationValueIndex = require("../../utils/declarationValueIndex");
const functionArgumentsSearch = require("../../utils/functionArgumentsSearch");
const isStandardSyntaxValue = require("../../utils/isStandardSyntaxValue");
const postcss = require("postcss");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
Expand Down Expand Up @@ -57,6 +58,11 @@ const rule = function(actual) {
(expression, expressionIndex) => {
const firstArg = expression.split(",")[0].trim();

// If the first arg is not standard, return early
if (!isStandardSyntaxValue(firstArg)) {
return;
}

// If the first character is a number, we can assume the user intends an angle
if (/[\d.]/.test(firstArg[0])) {
if (/^[\d.]+(?:deg|grad|rad|turn)$/.test(firstArg)) {
Expand Down

0 comments on commit 68cd18f

Please sign in to comment.