Render multiline brace blocks as breakables #426
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A side effect of #397 is that some multiline-able constructs (notably brace blocks) that aren't modeled with breakables could have the inner contents break but not the surrounding block. For example, something like
would incorrectly render as
instead of breaking at the block level. This caused rubyfmt to take multiple passes to settle on an output, which is incorrect.
This PR changes the way we do brace blocks to model them as breakables, which means they'll be more accurate when rendering on long lines and they won't fall prey to the multilining issues mentioned above. The implementation is admittedly not the cleanest in the world, but this is largely due to the fact that brace blocks aren't "traditional" breakables in the sense that we need to be able to support blockvars and because there are some additional requirements around when exactly to break them that aren't only about line length. As such, there's some hacks sprinkled in here, but I did my best to heavily comment and test them.