Skip to content

Commit

Permalink
Fix false positives for non-standard variables in `function-calc-no-u…
Browse files Browse the repository at this point in the history
…nspaced-operator` (#6053)
  • Loading branch information
ybiquitous committed May 1, 2022
1 parent e017583 commit b4139dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/rules/function-calc-no-unspaced-operator/__tests__/index.js
Expand Up @@ -115,6 +115,18 @@ testRule({
code: 'a { top: calc(-@x - 2rem); }',
description: 'Less variable syntax',
},
{
code: 'a { top: calc(@x-y * 2); }',
description: 'Less variable syntax with hyphens',
},
{
code: 'a { top: calc(-@x-y * 2); }',
description: 'Less variable syntax with hyphens and a unary operator',
},
{
code: 'a { top: calc(100% * @x-y); }',
description: 'Less variable syntax with hyphens at the end',
},
{
code: 'a { top: calc($x-y-z - 2rem); }',
description: 'postcss-simple-vars and SCSS variable with hyphens',
Expand All @@ -127,6 +139,18 @@ testRule({
code: 'a { top: calc(100% - #{$foo}); }',
description: 'Scss interpolation',
},
{
code: 'a { top: calc(#{$foo-bar} * 5); }',
description: 'Scss interpolation with hyphens',
},
{
code: 'a { top: calc(-#{$foo-bar} * 5); }',
description: 'Scss interpolation with hyphens and a unary operator',
},
{
code: 'a { top: calc(100% * #{$foo-bar}); }',
description: 'Scss interpolation with hyphens at the end',
},
{
code: 'a { top: calc(100% - #{map-get($container-max-widths, xl)}); }',
description: 'Scss interpolation with function',
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/function-calc-no-unspaced-operator/index.js
Expand Up @@ -4,6 +4,7 @@ const valueParser = require('postcss-value-parser');

const declarationValueIndex = require('../../utils/declarationValueIndex');
const getDeclarationValue = require('../../utils/getDeclarationValue');
const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const setDeclarationValue = require('../../utils/setDeclarationValue');
Expand Down Expand Up @@ -166,6 +167,8 @@ const rule = (primary, _secondaryOptions, context) => {

if (firstNode.type !== 'word') return false;

if (!isStandardSyntaxValue(firstNode.value)) return false;

const operatorIndex = firstNode.value.search(OPERATOR_REGEX);
const operator = firstNode.value.slice(operatorIndex, operatorIndex + 1);

Expand Down

0 comments on commit b4139dd

Please sign in to comment.