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

Update: Improve report location for space-before-function-paren #13128

Merged
merged 1 commit into from Apr 3, 2020
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
7 changes: 5 additions & 2 deletions lib/rules/space-before-function-paren.js
Expand Up @@ -127,7 +127,10 @@ module.exports = {
if (hasSpacing && functionConfig === "never") {
context.report({
node,
loc: leftToken.loc.end,
loc: {
start: leftToken.loc.end,
end: rightToken.loc.start
},
messageId: "unexpectedSpace",
fix(fixer) {
const comments = sourceCode.getCommentsBefore(rightToken);
Expand All @@ -145,7 +148,7 @@ module.exports = {
} else if (!hasSpacing && functionConfig === "always") {
context.report({
node,
loc: leftToken.loc.end,
loc: rightToken.loc,
messageId: "missingSpace",
fix: fixer => fixer.insertTextAfter(leftToken, " ")
});
Expand Down
30 changes: 25 additions & 5 deletions tests/lib/rules/space-before-function-paren.js
Expand Up @@ -136,7 +136,8 @@ ruleTester.run("space-before-function-paren", rule, {
type: "FunctionDeclaration",
messageId: "missingSpace",
line: 1,
column: 13
column: 13,
endColumn: 14
}
]
},
Expand All @@ -148,7 +149,8 @@ ruleTester.run("space-before-function-paren", rule, {
type: "FunctionDeclaration",
messageId: "missingSpace",
line: 1,
column: 13
column: 18,
endColumn: 19
}
]
},
Expand Down Expand Up @@ -230,7 +232,8 @@ ruleTester.run("space-before-function-paren", rule, {
type: "FunctionDeclaration",
messageId: "unexpectedSpace",
line: 1,
column: 13
column: 13,
endColumn: 14
}
]
},
Expand Down Expand Up @@ -273,6 +276,20 @@ ruleTester.run("space-before-function-paren", rule, {
}
]
},
{
code: "function foo () {}",
output: "function foo() {}",
options: ["never"],
errors: [
{
type: "FunctionDeclaration",
messageId: "unexpectedSpace",
line: 1,
column: 13,
endColumn: 15
}
]
},
{
code: "function foo//\n() {}",
output: null,
Expand All @@ -282,7 +299,9 @@ ruleTester.run("space-before-function-paren", rule, {
type: "FunctionDeclaration",
messageId: "unexpectedSpace",
line: 1,
column: 13
column: 13,
endLine: 2,
endColumn: 1
}
]
},
Expand Down Expand Up @@ -321,7 +340,8 @@ ruleTester.run("space-before-function-paren", rule, {
type: "FunctionExpression",
messageId: "unexpectedSpace",
line: 1,
column: 19
column: 19,
endColumn: 20
}
]
},
Expand Down