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 dollar variables in no-invalid-position-at-import-rule #5264

Merged
merged 1 commit into from May 1, 2021
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
37 changes: 37 additions & 0 deletions lib/rules/no-invalid-position-at-import-rule/__tests__/index.js
Expand Up @@ -111,3 +111,40 @@ testRule({
},
],
});

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

accept: [
{
code: stripIndent`
$foo: 1;
@import 'bar.css';
`,
description: 'dollar variable',
},
{
code: stripIndent`
// comment
@import 'foo.css';
`,
description: 'double slash comment',
},
],

reject: [
{
code: stripIndent`
a {}
$foo: 0;
@import 'bar.css';
`,
message: messages.rejected,
description: '@import after selector with dollar variable',
line: 3,
column: 1,
},
],
});
16 changes: 11 additions & 5 deletions lib/rules/no-invalid-position-at-import-rule/index.js
Expand Up @@ -2,6 +2,8 @@

'use strict';

const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
Expand All @@ -25,7 +27,15 @@ function rule(actual) {
root.walk((node) => {
const nodeName = node.name && node.name.toLowerCase();

if (node.type === 'comment' || (node.type === 'atrule' && nodeName === 'charset')) {
if (
(node.type === 'atrule' &&
nodeName !== 'charset' &&
nodeName !== 'import' &&
isStandardSyntaxAtRule(node)) ||
(node.type === 'rule' && isStandardSyntaxRule(node))
) {
invalidPosition = true;

return;
}

Expand All @@ -38,11 +48,7 @@ function rule(actual) {
ruleName,
});
}

return;
}

invalidPosition = true;
});
};
}
Expand Down