Skip to content

fix: avoid extra blank line after unused import removal (#1436) - #1437

Open
arimu1 wants to merge 1 commit into
google:masterfrom
arimu1:fix/1436-blank-line-after-import-removal
Open

fix: avoid extra blank line after unused import removal (#1436)#1437
arimu1 wants to merge 1 commit into
google:masterfrom
arimu1:fix/1436-blank-line-after-import-removal

Conversation

@arimu1

@arimu1 arimu1 commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Fixes #1436.

When unused imports between a package declaration and a class Javadoc/declaration are removed, the blank line that preceded the import block and the blank line that followed it were both left in place. The CLI path formats first and then fixes imports, so those stacked blanks were never re-normalized in the same pass (a second format pass fixed them).

This change:

  • Coalesces adjacent unused-import deletions (RangeMap.putCoalescing)
  • When a deleted import span is bordered by blank lines (or starts at the beginning of the file), absorbs one trailing blank line so package ↔ type spacing stays a single blank

Test plan

  • RemoveUnusedImportsTest — includes unused import removal leaves extra blank line between package declaration and class Javadoc / declaration #1436 package + unused import + class Javadoc, multi-unused, leading-import-only, and partial-unused cases
  • MainTest#unusedImportRemovalDoesNotLeaveDoubleBlankBeforeJavadoc — CLI Main.format path (format-then-fix-imports)
  • mvn -pl core -am test -Dtest=RemoveUnusedImportsTest,RemoveUnusedImportsCaseLabelsTest,FormatterTest,MainTest,ImportOrdererTest115/115 (Temurin 21)
  • Manual CLI repro: first pass is now idempotent (package + single blank + javadoc)

When every import between the package blank and the type blank is
removed, collapse one of the stacked blank lines so a single CLI pass
stays style-compliant (format-then-fix-imports path).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unused import removal leaves extra blank line between package declaration and class Javadoc / declaration

1 participant