Conversation
When "{" was emitted inside an already-open plusTwo level, passing plusTwo
again for breakAndIndentTrailingComment over-indented trailing block
comments. The next format pass then corrected them, so formatting was not
idempotent for "{ /* comment */ stmt; }" and array initializers.
Use ZERO for non-empty blocks/initializers (comment aligns with body) and
keep plusTwo when empty so standalone trailing comments still sit inside
the braces.
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.
Summary
Fixes #1260: formatting
{ /* comment */ stmt; }(and the analogous array-initializer form) was not idempotent — the first pass over-indented the broken-out trailing comment, and the second pass corrected it.Cause
visitBlock/visitArrayInitializeremit"{"withtokenBreakTrailingComment("{", plusTwo)after already opening aplusTwolevel. The trailing-comment break indent stacked anotherplusTwo, so a comment that was still attached to"{"in the input landed two spaces deeper than the following statements.Fix
ZEROfor the trailing-comment indent (already insideplusTwo).plusTwoso a lone trailing comment still sits inside the braces (preservesB20580212).Tests
I1260integration input/output (block, switch case, array).FormatterTest#trailingCommentAfterOpenBraceIsIdempotent.mvn -pl core -Dtest=FormatterIntegrationTest,FormatterTest test: 1083 tests, 0 failures (includes full integration + idempotent suite andB20580212).