-
-
Notifications
You must be signed in to change notification settings - Fork 541
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(lint): useArrowFunction should parenthesise the expr starting with {
#5170
Conversation
CodSpeed Performance ReportMerging #5170 will not alter performanceComparing Summary
|
We have a trait that checks if the expression needs parentheses: https://github.com/biomejs/biome/blob/main/crates%2Fbiome_js_syntax%2Fsrc%2Fparentheses%2Fmod.rs#L53 The trait should be implemented for the nodes you're working with. If not, it should be implemented |
1a952a8
to
0d9cda7
Compare
@ematipico I looked up Plus, I tried to replace the existing |
Looking at the snapshots, I would have expected to have the whole arrow function expression to be parenthesized, not just the body. For example, from the code of the original issue, I would expect a code fix similar to this: const obj = {
message: (arg) => {
return {
foo: "message response to foo",
bar: "message response to bar",
duck: "message response to duck",
}[arg]
}
}; So the |
…h `{` Signed-off-by: Naoki Ikeguchi <me@s6n.jp>
@ematipico const obj = {
message: (arg) => {
foo: "message response to foo",
bar: "message response to bar",
duck: "message response to duck",
}[arg],
}; This isn't a valid ECMAScript code. We need parens around the return value expression: const obj = {
message: (arg) => ({
// ^
foo: "message response to foo",
bar: "message response to bar",
duck: "message response to duck",
}[arg]),
// ^
}; I think this has different semantics from the I reverted to the original diff, with rebasing onto the latest main. |
Summary
Closes #4967
In ECMAScript, the return value of an arrow expression that starts with
{
needs to be parenthesised to be a valid expression, even if the expression is not aJsObjectExpression
. This pull request fixes the condition to parenthesise the expression or not.Test Plan
Snapshot tests added.