Skip to content
Permalink
Browse files

Fix: add parens for sequence expr in arrow-body-style (fixes #11917) (#…

  • Loading branch information...
g-plane authored and platinumazure committed Jul 21, 2019
1 parent 105c098 commit 79e8d099bbbebfa4d804484eeeeea9c074ede870
Showing with 14 additions and 2 deletions.
  1. +2 −2 lib/rules/arrow-body-style.js
  2. +12 −0 tests/lib/rules/arrow-body-style.js
@@ -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, ")")
@@ -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

0 comments on commit 79e8d09

Please sign in to comment.
You can’t perform that action at this time.