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 load-no-partial-leading-underscore end positions #913

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
63 changes: 63 additions & 0 deletions src/rules/load-no-partial-leading-underscore/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ testRule({
@import "_fff";
`,
line: 2,
column: 16,
endLine: 2,
endColumn: 20,
message: messages.expected,
description: "@import one file, underscore at the start."
},
Expand All @@ -151,6 +154,9 @@ testRule({
@import "_fff ";
`,
line: 2,
column: 16,
endLine: 2,
endColumn: 20,
message: messages.expected,
description:
"@import one file, underscore at the start, trailing space at the end."
Expand All @@ -160,6 +166,9 @@ testRule({
@import " _fff";
`,
line: 2,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description:
"@import one file, underscore at the start, trailing space at the start."
Expand All @@ -169,6 +178,9 @@ testRule({
@import "df/_fff";
`,
line: 2,
column: 16,
endLine: 2,
endColumn: 23,
message: messages.expected,
description: "@import one file, path with dir, underscore at the start."
},
Expand All @@ -177,6 +189,9 @@ testRule({
@import "df\\_fff";
`,
line: 2,
column: 16,
endLine: 2,
endColumn: 23,
message: messages.expected,
description: "@import one file, path with dir, windows delimiters."
},
Expand All @@ -185,6 +200,9 @@ testRule({
@import "df/fff", '_1.scss';
`,
line: 2,
column: 26,
endLine: 2,
endColumn: 33,
message: messages.expected,
description: "@import two files, path with dir, underscore at the start."
},
Expand All @@ -193,6 +211,9 @@ testRule({
@use "_fff";
`,
line: 2,
column: 13,
endLine: 2,
endColumn: 17,
message: messages.expected,
description: "@use one file, underscore at the start."
},
Expand All @@ -201,6 +222,9 @@ testRule({
@use "_fff ";
`,
line: 2,
column: 13,
endLine: 2,
endColumn: 17,
message: messages.expected,
description:
"@use one file, underscore at the start, trailing space at the end."
Expand All @@ -210,6 +234,9 @@ testRule({
@use " _fff";
`,
line: 2,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description:
"@use one file, underscore at the start, trailing space at the start."
Expand All @@ -219,6 +246,9 @@ testRule({
@use "df/_fff";
`,
line: 2,
column: 13,
endLine: 2,
endColumn: 20,
message: messages.expected,
description: "@use one file, path with dir, underscore at the start."
},
Expand All @@ -227,6 +257,9 @@ testRule({
@use "df\\_fff";
`,
line: 2,
column: 13,
endLine: 2,
endColumn: 20,
message: messages.expected,
description: "@use one file, path with dir, windows delimiters."
},
Expand All @@ -235,6 +268,9 @@ testRule({
@use "df/fff", '_1.scss';
`,
line: 2,
column: 23,
endLine: 2,
endColumn: 30,
message: messages.expected,
description: "@use two files, path with dir, underscore at the start."
},
Expand All @@ -243,6 +279,9 @@ testRule({
@forward "_fff";
`,
line: 2,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description: "@forward one file, underscore at the start."
},
Expand All @@ -251,6 +290,9 @@ testRule({
@forward "_fff ";
`,
line: 2,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description:
"@forward one file, underscore at the start, trailing space at the end."
Expand All @@ -260,6 +302,9 @@ testRule({
@forward " _fff";
`,
line: 2,
column: 18,
endLine: 2,
endColumn: 22,
message: messages.expected,
description:
"@forward one file, underscore at the start, trailing space at the start."
Expand All @@ -269,6 +314,9 @@ testRule({
@forward "df/_fff";
`,
line: 2,
column: 17,
endLine: 2,
endColumn: 24,
message: messages.expected,
description: "@forward one file, path with dir, underscore at the start."
},
Expand All @@ -277,6 +325,9 @@ testRule({
@forward "df\\_fff";
`,
line: 2,
column: 17,
endLine: 2,
endColumn: 24,
message: messages.expected,
description: "@forward one file, path with dir, windows delimiters."
},
Expand All @@ -285,6 +336,9 @@ testRule({
@forward "df/fff", '_1.scss';
`,
line: 2,
column: 27,
endLine: 2,
endColumn: 34,
message: messages.expected,
description: "@forward two files, path with dir, underscore at the start."
},
Expand All @@ -296,6 +350,9 @@ testRule({
}
`,
line: 4,
column: 33,
endLine: 4,
endColumn: 40,
message: messages.expected,
description:
"meta.load-css two params, path with dir, windows delimiters."
Expand All @@ -308,6 +365,9 @@ testRule({
}
`,
line: 4,
column: 33,
endLine: 4,
endColumn: 37,
message: messages.expected,
description:
"meta.load-css two params, underscore at the start, trailing space at the start."
Expand All @@ -320,6 +380,9 @@ testRule({
}
`,
line: 4,
column: 33,
endLine: 4,
endColumn: 37,
message: messages.expected,
description:
"meta.load-css one param, underscore at the start, trailing space at the start."
Expand Down
12 changes: 7 additions & 5 deletions src/rules/load-no-partial-leading-underscore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ const meta = {
function rule(actual) {
return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, { actual });
const hasArgumentsRegExp = /\(\s*([^)]+?)\s*\)/;

if (!validOptions) {
return;
}

function checkPathForUnderscore(path, decl) {
const hasArgumentsRegExp = /\(\s*([^)]+?)\s*\)/;

function checkPathForUnderscore(path, atrule) {
// Stripping trailing quotes and whitespaces, if any
const pathStripped = path
.replace(/^\s*(["'])\s*/, "")
Expand All @@ -46,9 +47,10 @@ function rule(actual) {

utils.report({
message: messages.expected,
node: decl,
node: atrule,
result,
ruleName
ruleName,
word: pathStripped
});
}

Expand All @@ -69,7 +71,7 @@ function rule(actual) {
const args = hasArgumentsRegExp.exec(atrule.params);
if (args) {
const arg = args[0].split(",");
checkPathForUnderscore(arg[0].replace(/\(|\)/, ""), atrule);
checkPathForUnderscore(arg[0].replace(/[()]/g, ""), atrule);
}
}
}
Expand Down