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 at-mixin-pattern end positions #903

Merged
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
70 changes: 35 additions & 35 deletions src/rules/at-mixin-pattern/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description: "Regexp: sequence part. Example: symbol in between."
}
Expand Down Expand Up @@ -123,9 +123,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description: "String: sequence part. Example: symbol in between."
},
Expand All @@ -135,9 +135,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 16,
message: messages.expected,
description: "String: sequence part. Example: not a full sequence."
}
Expand Down Expand Up @@ -209,9 +209,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the end."
},
Expand All @@ -221,9 +221,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the beginning."
},
Expand All @@ -233,9 +233,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description: "Regexp: strict match. Example: symbol in between."
},
Expand All @@ -247,9 +247,9 @@ testRule({
}
`,
line: 2,
column: 7,
column: 14,
endLine: 3,
endColumn: 0,
endColumn: 10,
message: messages.expected,
description:
"Regexp: strict match. Example: mixin name divided by newlines."
Expand Down Expand Up @@ -288,9 +288,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: matches at the end."
Expand All @@ -301,9 +301,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 14,
endLine: 2,
endColumn: 18,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: symbol in between."
Expand Down Expand Up @@ -332,28 +332,28 @@ testRule({
{
code: "@mixin boo-Foo-bar ( $p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
column: 8,
endLine: 1,
endColumn: 19,
message: messages.expected,
description:
"Regexp: SUIT component. Example: starts with lowercase, two elements"
},
{
code: "@mixin foo-bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
column: 8,
endLine: 1,
endColumn: 15,
message: messages.expected,
description: "Regexp: SUIT component. Example: starts with lowercase"
},
{
code: "@mixin Foo-Bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
column: 8,
endLine: 1,
endColumn: 15,
message: messages.expected,
description:
"Regexp: SUIT component. Example: element starts with uppercase"
Expand Down
16 changes: 4 additions & 12 deletions src/rules/at-mixin-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,20 @@ function rule(pattern) {

const regexpPattern = isString(pattern) ? new RegExp(pattern) : pattern;

root.walkAtRules(decl => {
if (decl.name !== "mixin") {
return;
}

root.walkAtRules("mixin", atRule => {
// Stripping the mixin of its arguments
const mixinName = decl.params.replace(/(\s*)\([\s\S]*\)/g, "");
const mixinName = atRule.params.replace(/(\s*)\([\s\S]*\)/g, "");

if (regexpPattern.test(mixinName)) {
return;
}

const mixinTopLine = Object.assign({}, decl.source.start);
mixinTopLine.line += 1;
mixinTopLine.column = 0;

utils.report({
message: messages.expected,
node: decl,
node: atRule,
result,
ruleName,
end: mixinTopLine
word: mixinName
});
});
};
Expand Down