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

*-notation: fix false negatives for $ vars (#5010) #5031

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
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