Skip to content

Commit

Permalink
Fix false negatives for dollar variables in *-notation (#5031)
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-cumplido committed Nov 17, 2020
1 parent d347a29 commit 1e6f944
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 9 deletions.
67 changes: 67 additions & 0 deletions lib/rules/alpha-value-notation/__tests__/index.js
Expand Up @@ -303,3 +303,70 @@ testRule({
},
],
});

testRule({
ruleName,
syntax: 'scss',
config: ['number'],
fix: true,

accept: [
{
code: '$a: rgb(0, 0, 0);',
},
{
code: '$a: rgb(0 0 0);',
},
{
code: '$a: rgba(0, 0, 0, 0.5);',
},
{
code: '$a: rgb(0 0 0 / 0.5);',
},
{
code: 'a { color: rgb(0 0 0 / $a) }',
},
],

reject: [
{
code: '$a: rgb(0 0 0 / 50%);',
fixed: '$a: rgb(0 0 0 / 0.5);',
message: messages.expected('50%', '0.5'),
line: 1,
column: 17,
},
],
});

testRule({
ruleName,
syntax: 'scss',
config: ['percentage'],
fix: true,

accept: [
{
code: '$a: rgba(0, 0, 0, 50%);',
},
{
code: '$a: rgb(0 0 0 / 50%);',
},
{
code: '$a: 50%; a { color: rgb(0 0 0 / $a) }',
},
{
code: '$a: 0.5; a { color: rgb(0 0 0 / $a) }',
},
],

reject: [
{
code: '$a: rgb(0 0 0 / 0.5);',
fixed: '$a: rgb(0 0 0 / 50%);',
message: messages.expected('0.5', '50%'),
line: 1,
column: 17,
},
],
});
3 changes: 0 additions & 3 deletions lib/rules/alpha-value-notation/index.js
Expand Up @@ -6,7 +6,6 @@ const _ = require('lodash');
const valueParser = require('postcss-value-parser');

const declarationValueIndex = require('../../utils/declarationValueIndex');
const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
const optionsMatches = require('../../utils/optionsMatches');
const report = require('../../utils/report');
Expand Down Expand Up @@ -43,8 +42,6 @@ function rule(primary, options, context) {
if (!validOptions) return;

root.walkDecls((decl) => {
if (!isStandardSyntaxDeclaration(decl)) return;

let needsFix = false;
const parsedValue = valueParser(getValue(decl));

Expand Down
69 changes: 69 additions & 0 deletions lib/rules/color-function-notation/__tests__/index.js
Expand Up @@ -360,3 +360,72 @@ testRule({
},
],
});

testRule({
ruleName,
syntax: 'scss',
config: ['modern'],
fix: true,

accept: [
{
code: '$a: rgb(0 0 0);',
},
{
code: '$a: rgb(0 0 0 / 0);',
},
{
code: 'a { color: rgb($a $b $c / $d) }',
},
],

reject: [
{
code: '$a: rgb(0, 0, 0);',
fixed: '$a: rgb(0 0 0);',
message: messages.expected('modern'),
line: 1,
column: 5,
},
{
code: 'a { color: rgba($a, $b, $c, $d) }',
fixed: 'a { color: rgb($a $b $c / $d) }',
message: messages.expected('modern'),
line: 1,
column: 12,
},
],
});

testRule({
ruleName,
syntax: 'scss',
config: ['legacy'],

accept: [
{
code: '$a: rgb(0, 0, 0);',
},
{
code: '$a: rgba(0, 0, 0, 0);',
},
{
code: 'a { color: rgba($a, $b, $c, $d) }',
},
],

reject: [
{
code: '$a: rgb(0 0 0 / 0);',
message: messages.expected('legacy'),
line: 1,
column: 5,
},
{
code: 'a { color: rgb($a $b $c / $d) }',
message: messages.expected('legacy'),
line: 1,
column: 12,
},
],
});
3 changes: 0 additions & 3 deletions lib/rules/color-function-notation/index.js
Expand Up @@ -5,7 +5,6 @@
const valueParser = require('postcss-value-parser');

const declarationValueIndex = require('../../utils/declarationValueIndex');
const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
Expand All @@ -29,8 +28,6 @@ function rule(primary, secondary, context) {
if (!validOptions) return;

root.walkDecls((decl) => {
if (!isStandardSyntaxDeclaration(decl)) return;

let needsFix = false;
const parsedValue = valueParser(getValue(decl));

Expand Down
52 changes: 52 additions & 0 deletions lib/rules/hue-degree-notation/__tests__/index.js
Expand Up @@ -196,3 +196,55 @@ testRule({
},
],
});

testRule({
ruleName,
syntax: 'scss',
config: ['angle'],
fix: true,

accept: [
{
code: '$a: hsl(0deg 0 0);',
},
{
code: 'a { color: hsl($a 0 0) }',
},
],

reject: [
{
code: '$a: hsl(0 0 0);',
fixed: '$a: hsl(0deg 0 0);',
message: messages.expected('0', '0deg'),
line: 1,
column: 9,
},
],
});

testRule({
ruleName,
syntax: 'scss',
config: ['number'],
fix: true,

accept: [
{
code: '$a: hsl(0 0 0);',
},
{
code: 'a { color: hsl($a 0 0) }',
},
],

reject: [
{
code: '$a: hsl(0deg 0 0);',
fixed: '$a: hsl(0 0 0);',
message: messages.expected('0deg', '0'),
line: 1,
column: 9,
},
],
});
3 changes: 0 additions & 3 deletions lib/rules/hue-degree-notation/index.js
Expand Up @@ -5,7 +5,6 @@
const valueParser = require('postcss-value-parser');

const declarationValueIndex = require('../../utils/declarationValueIndex');
const isStandardSyntaxDeclaration = require('../../utils/isStandardSyntaxDeclaration');
const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
Expand All @@ -31,8 +30,6 @@ function rule(primary, secondary, context) {
if (!validOptions) return;

root.walkDecls((decl) => {
if (!isStandardSyntaxDeclaration(decl)) return;

let needsFix = false;
const parsedValue = valueParser(getValue(decl));

Expand Down

0 comments on commit 1e6f944

Please sign in to comment.