Skip to content

Fix: importOrder() with single catch-all group strips blank lines added by greclipse(), causing non-idempotent formatting#2914

Open
austek wants to merge 2 commits intodiffplug:mainfrom
austek:fix/groovy_formatting
Open

Fix: importOrder() with single catch-all group strips blank lines added by greclipse(), causing non-idempotent formatting#2914
austek wants to merge 2 commits intodiffplug:mainfrom
austek:fix/groovy_formatting

Conversation

@austek
Copy link
Copy Markdown

@austek austek commented May 1, 2026

Summary

  • importOrder() with no explicit groups (single catch-all) unconditionally replaced the entire import block, stripping any blank lines that a prior step like greclipse() had independently inserted between import groups.
  • This created an infinite cycle: greclipse() adds blank lines → importOrder() strips them → greclipse() re-adds them → repeat (GitHub issue Maven Groovy importOrder prevents greclipse from checking and applying #899).
  • Fix: when the sorted output contains no blank-line separators (single catch-all group) and the imports are already in the correct order, return the raw input unchanged, preserving any blank lines already present.

Test plan

  • groovyImportsPreservesBlankLinesBetweenGroups — asserts that importOrder() with no args leaves an already-sorted Groovy import block with blank lines untouched.
  • groovySortImportsStripsInterleavedBlankLines — asserts that sorting still works when imports are out of order; interleaved blank lines are removed as a side effect of the rewrite.

Fixes #899

austek added a commit to austek/spotless that referenced this pull request May 1, 2026
…plug#2914)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@austek austek force-pushed the fix/groovy_formatting branch from 28edf92 to 0c25202 Compare May 1, 2026 11:42
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.

Maven Groovy importOrder prevents greclipse from checking and applying

1 participant