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 interpolation in property name in custom-property-pattern #5949

Merged
merged 8 commits into from Mar 7, 2022
9 changes: 9 additions & 0 deletions lib/rules/custom-property-pattern/__tests__/index.js
Expand Up @@ -138,5 +138,14 @@ testRule({
{
code: 'a { color: var(tokens.$bar-color); }',
kawaguchi1102 marked this conversation as resolved.
Show resolved Hide resolved
},
{
code: 'a { --#{$variable-prefix}table-bg: rgba(#a1f2b0, 0.3); }',
kawaguchi1102 marked this conversation as resolved.
Show resolved Hide resolved
},
{
code: 'a { color: var( #{$variable-color} ); }',
kawaguchi1102 marked this conversation as resolved.
Show resolved Hide resolved
},
{
code: 'a { color: var( --#{$variable-color} ); }',
kawaguchi1102 marked this conversation as resolved.
Show resolved Hide resolved
},
],
});
13 changes: 7 additions & 6 deletions lib/rules/custom-property-pattern/index.js
Expand Up @@ -8,6 +8,7 @@ const validateOptions = require('../../utils/validateOptions');
const declarationValueIndex = require('../../utils/declarationValueIndex');
const { isRegExp, isString } = require('../../utils/validateTypes');
const { isValueFunction } = require('../../utils/typeGuards');
const isStandardSyntaxProperty = require('../../utils/isStandardSyntaxProperty');

const ruleName = 'custom-property-pattern';

Expand Down Expand Up @@ -47,20 +48,20 @@ const rule = (primary) => {

const { value: firstNodeValue } = nodes[0];

if (!isStandardSyntaxProperty(firstNodeValue)) return;

if (!isCustomProperty(firstNodeValue)) return;

if (regexpPattern.test(firstNodeValue.slice(2))) return;

complain(declarationValueIndex(decl) + sourceIndex, decl);
});

if (!isCustomProperty(prop)) {
return;
}
if (!isStandardSyntaxProperty(prop)) return;

if (!isCustomProperty(prop)) return;

if (regexpPattern.test(prop.slice(2))) {
return;
}
if (regexpPattern.test(prop.slice(2))) return;

complain(0, decl);
});
Expand Down