Crystal: Formatter should remove unnecessary parenthesis around single assignment

Created on 15 Nov 2019  路  4Comments  路  Source: crystal-lang/crystal

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).

feature topicformatter

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xtagon picture xtagon  路  132Comments

benoist picture benoist  路  59Comments

rdp picture rdp  路  112Comments

asterite picture asterite  路  71Comments

akzhan picture akzhan  路  67Comments