gleam-lang / suggestions

📙 A place for ideas and feedback
26 stars 2 forks source link

Formatter should add brackets when piping into one arity function. #81

Closed CrowdHailer closed 3 years ago

CrowdHailer commented 4 years ago
"something"
|> Ok()

"something"
|> Ok

Both of these are left alone by the formatter. I think for consistency one should be preferred.

My choice would be with brackets but I don't have a strong opinion

lpil commented 4 years ago

I'd like to taller the more common approach and not use parens. As far as I know Elixir is the only language that uses parens here.

Additionally when parens are added what is happening is more ambiguous. There are two ways the pipe can be rewritten with parens, while there is only one without, so without is more clear to the reader.

We can't rewrite them easily because they do actually do different things, and we should need to to do full analysis of the code in order to determine when it is safe to remove the parens. This would mean we would need to make a big change to the formatter, it would run slower, and it would no longer work on code that does not type check.