Skip to content

Commit

Permalink
Fix: add parens for sequence expr in arrow-body-style (fixes #11917) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and platinumazure committed Jul 21, 2019
1 parent 105c098 commit 79e8d09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/arrow-body-style.js
Expand Up @@ -175,10 +175,10 @@ module.exports = {
}

/*
* If the first token of the reutrn value is `{`,
* If the first token of the reutrn value is `{` or the return value is a sequence expression,
* enclose the return value by parentheses to avoid syntax error.
*/
if (astUtils.isOpeningBraceToken(firstValueToken)) {
if (astUtils.isOpeningBraceToken(firstValueToken) || blockBody[0].argument.type === "SequenceExpression") {
fixes.push(
fixer.insertTextBefore(firstValueToken, "("),
fixer.insertTextAfter(lastValueToken, ")")
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/arrow-body-style.js
Expand Up @@ -162,6 +162,18 @@ ruleTester.run("arrow-body-style", rule, {
}
]
},
{
code: "var foo = () => { return a, b }",
output: "var foo = () => (a, b)",
errors: [
{
line: 1,
column: 17,
type: "ArrowFunctionExpression",
messageId: "unexpectedSingleBlock"
}
]
},
{
code: "var foo = () => { return };",
output: null, // not fixed
Expand Down

0 comments on commit 79e8d09

Please sign in to comment.