-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Unnecessary parentheses wrapping for BinaryExpression in UnaryExpression #18802
Copy link
Copy link
Closed
Description
Prettier 3.8.1
Playground link
--parser babelInput:
All are prettier tests at
prettier/tests/format/js/unary-expression/comments.js
Lines 31 to 33 in 812a4d0
| !(x || y); | |
| !(/* foo */ x || y); | |
| !(x || y /* foo */); |
!(x || y);
!(/* foo */ x || y);
!(x || y /* foo */);Output:
!(x || y);
!(/* foo */ (x || y));
!((x || y) /* foo */);Expected output:
!(x || y);
!(/* foo */ x || y);
!(x || y /* foo */);Note: Same as input
Why?
The added parentheses are unnecessary - !(x || y) already groups the expression clearly.
Also, this is inconsistent: multi-line chains with comments don't get extra parentheses:
!(
x || // foo
y // bar
);
<!-- short explanation of expected output -->Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels