Repository navigation
fix: keep hugging object siblings when they're all multi-line - #893
Merged
Merged
Conversation
Only break the container for same-kind siblings (#641) when they're mixed. When every value with a same-kind neighbor is multi-line because of how it's written (a newline after its open brace or bracket with that kind's preferSingleLine off), they stay hugged like before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #793.
#793 fixed #641, where one object in an array of short objects was expanded in the middle of the others:
It did that by not letting any object or array hug when it has a sibling of the same kind, which also broke up arrays where every object is multi-line and the hugging is uniform:
That now formats as before #793. The container only breaks when the siblings are mixed. If every object-like or array-like value that has a sibling of the same kind is multi-line as written (a newline after its
{or[, using the same check its own formatting uses, so itspreferSingleLineis respected), they can hug as before. Otherwise the container breaks like #793 does, including the #641 case and mixes like[{ a: 1 }, {\n b: 2,\n}, { c: 3 }].When a hugged container has mixed siblings, the multi-line ones were usually only split because of the old hugging, so they now go on one line when they fit:
A sibling that doesn't fit, or has a comment on another line, stays multi-line. If everything fits after that, the container stays on one line too.
A container that's already broken out (a newline after its
[,(or<) is left as written, including siblings split over several lines.In the regression corpus I use, one file changed: an array of objects that each have a comment on its own line now hugs with
preferSingleLine: true. The comment keeps each object multi-line, so they're all multi-line.Tests
issue0641_02.txtcovers JSX attributes, call arguments, mixed siblings and putting them on one line, siblings that don't fit, comments, already broken containers, tuples, type arguments, object patterns, nested arrays, nested objects and empty objects.issue0641_03.txtandissue0641_04.txtcover the global and per-nodepreferSingleLine.ArrayExpression_PreferSingleLine_True.txt,TupleType_PreferSingleLine_True.txtandold_repo/issue067.txthad all their siblings multi-line, so they're back to their expectations from before fix: break container instead of expanding one of many object siblings (#641) #793.