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

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

Merged
merged 1 commit into from Jul 21, 2019
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
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