Parenthesis around a single assignment is completely unnecessary, the formatter should remove it:
(foo = 0)
Parenthesis is only necessary when combined with other expressions (for example using logical operators).
Shouldn't it maybe remove unnecessary parentheses in general? Instead of only around assignments. Like x = ((1+1))
becomes x = 1 + 1
, if (x == 2)
becomes if x == 2
.
No, it should add parentheses around assignment when used as an expression.
E.g. if (a = 5)
Regarding the main topic: shouldn't it remove parentheses around any top-level expression?
The formatter tidied up code by adding or removing spaces and newlines. In some very special cases it might remove code, like when you do obj. foo()
but that's it.
My issue with removing code is that you might be writing an expression, hit save and the formatter gets in the way. So I'd rather keep the formatter unobtrusive.
Most helpful comment
The formatter tidied up code by adding or removing spaces and newlines. In some very special cases it might remove code, like when you do
obj. foo()
but that's it.My issue with removing code is that you might be writing an expression, hit save and the formatter gets in the way. So I'd rather keep the formatter unobtrusive.