Format multiple trailing closures. #230
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.
When a function call has multiple trailing closures, every closure is forced to wrap.
There are two potentially surprising things about the behavior here:
Unlike an
if/else
statement, which can be formatted like this if it would fit entirely on one line:...we do not allow the same thing to occur for multiple trailing closures at this time:
The forced break occurs after the closure signature
{ arg, arg, arg in‸
if it's present; otherwise, it occurs after the open brace. This lets the closure signature stay on the same line as the open brace if it fits, but it will still wrap (via the normal break that occurs here{‸arg, arg, arg in
) if it wouldn't fit.However, because the break after
in‸
is forced, that means that if the break after{‸
also fires, then even a single-statement closure will have a line break after the signature, when regular closures otherwise wouldn't. In other words,I can live with (1); I don't think it's a huge problem because I imagine the number of function calls with multiple trailing closures that would fit entirely on one line are exceedingly rare to begin with, and I think in the case of multiple trailing closures it's more readable to have them wrapped anyway so that the label isn't hidden in the middle of the line.
I'm less happy about (2), since it's a weird inconsistency, but I'm not sure our current model is flexible enough to say "given
{₁arg, arg, arg in₂
, force break 2 only if we didn't already break at 1". It's almost like a reset, but not quite the same because we're not conditioning it on continuation line state.@dylansturg Any ideas here?