Skip to content

Partial formatting: re-indent statements outside the range to match the formatted output #182

Open

Description

@abashev

Upstream: google/google-java-format#1503
Kind: idea | Priority: low

google-java-format#1503 (merged 2026-10-29, copybara export) addresses --lines / --offset formatting: when an edit adds or removes a block nesting level, statements outside the requested range kept their old indentation and ended up misaligned with their closing braces. With --cleanup on, every unformatted statement-level segment that starts on its own line is now shifted as a unit to its formatted indentation, keeping its inner line breaks. Text blocks and other multi-line tokens are untouched, and a check ensures only leading whitespace changes. A separate upstream commit (f7eeb776a343a4e1d65d1ce229c837773257e276) also fixes leftover double blank lines after removing an unused import in partial mode (see google-java-format#1436 and google-java-format#598, both closed 2026-10-29).

Why it matters: IDE users format only the changed lines, which is exactly this case. We should check whether our range formatting leaves the same misalignment and the same double blank line after unused-import removal.

Affected files in our repo:

  • open-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java (range formatting)
  • open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java
  • open-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java

Suggested action: investigate. Try both scenarios in our formatter; adopt the idea only if the problem reproduces. Examples: not available - the exact test inputs are in a 700-line test diff and I did not derive our output.


Filed from an upstream-watch ticket after manual review.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions