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 namespaced variables in property-no-unknown #4803

Merged
merged 4 commits into from Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions lib/rules/property-no-unknown/__tests__/index.js
Expand Up @@ -86,6 +86,10 @@ testRule({
code: '.foo { $bgColor: white; }',
description: 'ignore SCSS variables',
},
{
code: '.foo { namespace.$bgColor: white; }',
description: 'ignore SCSS variables within namespace',
},
{
code: '.foo { #{$prop}: black; }',
description: 'ignore property interpolation',
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxDeclaration.test.js
Expand Up @@ -121,6 +121,18 @@ describe('isStandardSyntaxDeclaration', () => {
});
});

it('scss var within namespace', () => {
scssDecls('namespace.$var: b', (decl) => {
expect(isStandardSyntaxDeclaration(decl)).toBeFalsy();
});
});

it('nested scss var within namespace', () => {
scssDecls('a { namespace.$var: b }', (decl) => {
expect(isStandardSyntaxDeclaration(decl)).toBeFalsy();
});
});

it('sass list', () => {
sassDecls('$list: (key: value, key2: value2)', (decl) => {
expect(isStandardSyntaxDeclaration(decl)).toBeFalsy();
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/isStandardSyntaxDeclaration.js
Expand Up @@ -57,5 +57,10 @@ module.exports = function (decl) {
return false;
}

// Sass variables within a namespace (e.g. namespace.$var: x)
if (prop.includes('.$') && prop[0] !== '.' && prop[prop.length - 1] !== '$') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just go with if (prop.includes('.$')) as the util is more interested in excluding non-standard properties than the validity of name-spaced dollar variables.

return false;
}
Copy link
Contributor Author

@ryym ryym May 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this function should return for invalid declarations such as .$var and namespace.$. For now this branch excludes those invalid props.


return true;
};