Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update: Improve report location for space-before-function-paren (#13128)
  • Loading branch information
golopot committed Apr 3, 2020
1 parent d0d32a8 commit 5e07574
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
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

0 comments on commit 5e07574

Please sign in to comment.