-
Notifications
You must be signed in to change notification settings - Fork 191
test(organizeimports): add failing IO tests for inline comment behavior (issue #2267) #2324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test(organizeimports): add failing IO tests for inline comment behavior (issue #2267) #2324
Conversation
|
Test cases included I added failing test cases in the following files: InlineCommentMultiple.scala InlineCommentMoves.scala InlineCommentRemoved.scala These tests capture scenarios where inline comments are not preserved, shifted incorrectly, or dropped during import organization. |
|
I think the test cases look fine, we might not need that many though. |
|
Thanks for the clarification and for reviewing the tests! Also, should I start working on the actual fix for the issue now? |
|
Sure, just make sure that if you use AI that you properly vet the output and try to minimize the changes. |
bjaglin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great start 👍 I think we could add heading/trailing examples, as well as multi-line /* */ comments to have a better coverage.
Feel free to start working on implementation.
scalafix-tests/input/src/main/scala/test/organizeImports/StandaloneComment.scala
Outdated
Show resolved
Hide resolved
| import c.C | ||
|
|
||
| object InlineCommentMultiple { | ||
| val keep = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can remove that if removeUnused is not tested
…aloneComment.scala Co-authored-by: Brice Jaglin <bjaglin@gmail.com>
Removed unused import 'c.C' to clean up code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds new IO test cases to capture the current (incorrect) behavior of the OrganizeImports rule when handling inline comments. The tests document scenarios where inline comments are lost, reordered incorrectly, or not properly associated with their imports, establishing a baseline for future fixes to issue #2267.
- Adds fixture file
InlineCommentFixtures.scalawith test packages and classes - Creates 4 test scenarios covering standalone comments, inline comment preservation during sorting, inline comment behavior with unused import removal, and inline comment movement
- Establishes expected behavior patterns for subsequent OrganizeImports rule improvements
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scalafix-tests/shared/src/main/scala/test/organizeImports/InlineCommentFixtures.scala | Provides fixture classes in packages a, b, c, z, my.pkg, other, x, y for testing import organization with inline comments |
| scalafix-tests/input/src/main/scala/test/organizeImports/StandaloneComment.scala | Tests that standalone comments (not inline) are preserved when imports are sorted |
| scalafix-tests/output/src/main/scala/test/organizeImports/StandaloneComment.scala | Expected output showing standalone comment preserved with sorted imports |
| scalafix-tests/input/src/main/scala/test/organizeImports/InlineCommentRemoved.scala | Tests inline comment behavior when associated import is removed as unused |
| scalafix-tests/output/src/main/scala/test/organizeImports/InlineCommentRemoved.scala | Expected output showing unused import and its inline comment are both removed |
| scalafix-tests/input/src/main/scala/test/organizeImports/InlineCommentMultiple.scala | Tests preservation of multiple inline comments during import sorting |
| scalafix-tests/output/src/main/scala/test/organizeImports/InlineCommentMultiple.scala | Expected output showing inline comments move with their associated imports when sorted |
| scalafix-tests/input/src/main/scala/test/organizeImports/InlineCommentMoves.scala | Tests inline comment staying with its import when imports are reordered |
| scalafix-tests/output/src/main/scala/test/organizeImports/InlineCommentMoves.scala | Expected output showing inline comment moved with its import during sorting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import a.A // anote | ||
|
|
||
| object InlineCommentMultiple { | ||
| val keep = 1 |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imports a.A, b.B, and c.C are declared but not used in the object body (only val keep = 1 is defined). Without explicitly setting removeUnused = false in the configuration, these imports may be removed during the test execution if unused import removal is enabled by default. Consider either:
- Adding
OrganizeImports.removeUnused = falseto the configuration block, or - Using the imported classes in the object body (e.g.,
val keep: A = ???)
| val keep = 1 | |
| val keep = 1 | |
| val keepA: a.A = ??? // use a.A to keep import | |
| val keepB: b.B = ??? // use b.B to keep import |
| import a.A | ||
|
|
||
| object InlineCommentMoves { | ||
| val keep = (null: AnyRef) |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imports z.Z and a.A are declared but not used in the object body (only val keep = (null: AnyRef) is defined). Without explicitly setting removeUnused = false in the configuration, these imports may be removed during the test execution if unused import removal is enabled by default. Consider either:
- Adding
OrganizeImports.removeUnused = falseto the configuration block, or - Using the imported classes in the object body (e.g.,
val keep: A = ???)
| val keep = (null: AnyRef) | |
| val keep: A = ??? // use imported class A to prevent unused import removal |
This PR adds new IO test cases for OrganizeImports to capture the incorrect handling of inline comments (e.g., comments to the right of imports being lost, reordered incorrectly, or not associated with the correct import). These test
s encode the expected behavior so the underlying rule can later be updated to preserve inline comments consistently.
Locally, the new tests pass, but some unrelated expect*/testOnly suites occasionally behave inconsistently on my machine (sometimes showing passed, canceled, or failed). I’ve attached a screenshot in the discussion, but this inconsistency does not involve the new OrganizeImports tests themselves.
Please review the added test cases and confirm whether this structure matches what the maintainers expect before I proceed to implement the actual fix to OrganizeImports.

