Skip to content

Commit

Permalink
Fix at-function-pattern end positions (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Dec 11, 2023
1 parent 62139e4 commit 94f64c4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 47 deletions.
70 changes: 35 additions & 35 deletions src/rules/at-function-pattern/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description: "Regexp: sequence part. Example: symbol in between."
}
Expand Down Expand Up @@ -125,9 +125,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description: "String: sequence part. Example: symbol in between."
},
Expand All @@ -137,9 +137,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 19,
message: messages.expected,
description: "String: sequence part. Example: not a full sequence."
}
Expand Down Expand Up @@ -202,9 +202,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the end."
},
Expand All @@ -214,9 +214,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description: "Regexp: strict match. Example: matches at the beginning."
},
Expand All @@ -226,9 +226,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description: "Regexp: strict match. Example: symbol in between."
},
Expand All @@ -240,9 +240,9 @@ testRule({
}
`,
line: 2,
column: 7,
column: 17,
endLine: 3,
endColumn: 0,
endColumn: 10,
message: messages.expected,
description:
"Regexp: strict match. Example: function name divided by newlines."
Expand Down Expand Up @@ -281,9 +281,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: matches at the end."
Expand All @@ -294,9 +294,9 @@ testRule({
}
`,
line: 2,
column: 7,
endLine: 3,
endColumn: 0,
column: 17,
endLine: 2,
endColumn: 21,
message: messages.expected,
description:
"Regexp: pattern at the beginning. Example: symbol in between."
Expand Down Expand Up @@ -325,28 +325,28 @@ testRule({
{
code: "@function boo-Foo-bar ( $p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
column: 11,
endLine: 1,
endColumn: 22,
message: messages.expected,
description:
"Regexp: SUIT component. Example: starts with lowercase, two elements"
},
{
code: "@function foo-bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
column: 11,
endLine: 1,
endColumn: 18,
message: messages.expected,
description: "Regexp: SUIT component. Example: starts with lowercase"
},
{
code: "@function Foo-Bar ($p) {}",
line: 1,
column: 1,
endLine: 2,
endColumn: 0,
column: 11,
endLine: 1,
endColumn: 18,
message: messages.expected,
description:
"Regexp: SUIT component. Example: element starts with uppercase"
Expand Down
16 changes: 4 additions & 12 deletions src/rules/at-function-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 !== "function") {
return;
}

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

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

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

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

0 comments on commit 94f64c4

Please sign in to comment.