fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.07k stars 50 forks source link

Represent binary operators as breakables #452

Closed reese closed 8 months ago

reese commented 8 months ago

Closes #379

This PR yanks out the hacked-together multilining strategy for binary operators and makes them breakables instead. This was largely easier than I though -- IIRC the original reason for not doing this was that call chains weren't also breakables, so that resulted in weird interactions, but since we did that in #443, this is a pretty straightforward change.

The way this works is that instead of our old hacked-together system, we can wrap the "top-level" binary in a breakable, and then for nested breakables, we just recurse into the formatting function instead of making a new breakable, which keeps the old behavior of keeping chained binary operations all at the same level.

This also fixed a number of accidental interactions that I wasn't aware of but that I think are actually bugs -- in the fixtures that we changed, this PR makes it so that binary operators now respect user-multiling in all cases, which they didn't used to do but which is consistent with the approach taken for other breakable items.