Skip to content
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

OrganizeImports.groups not correctly grouping imports if doing a nested import statement #2100

Open
mdedetrich opened this issue Oct 7, 2024 · 1 comment

Comments

@mdedetrich
Copy link
Contributor

Here is the PR in context and here is the specific .scalafix configuration

https:/mdedetrich/pekko-streams-circe/pull/12/files#diff-8fe42aaf3e5d1a3f8804efa64a6206f5af6a826dea8f6ce51ad0ce8105188858R1-R32

My current expectation of that configuration is that java/scala imports go to the bottom of the import list and all other imports gravitate to the top but as you can see from https:/mdedetrich/pekko-streams-circe/pull/12/files#diff-ba5a4a197dba09e4d184afb14c8a2f50b68a870a27cfd9ceebc328fd2a96618b the various pekko.* imports are being placed after the scala/java imports.

I tried adding pekko/org.apache.pekko to the group list but that didn't have any effect, this is just a suspicion but maybe the underlying issue is that there is a import org.apache.pekko and then after that import statement we do import pekko.NotUsed etc etc

@bjaglin
Copy link
Collaborator

bjaglin commented Oct 7, 2024

The behaviour you are observing is indeed due to the usage of relative imports.

https://scalacenter.github.io/scalafix/docs/rules/OrganizeImports.html#groups

No matter how the groups option is configured, a special
order-preserving import group may appear after all the configured import
groups when:

  1. The expandRelative option is set to false and there are relative
    imports.

...

This special import group is necessary because the above two kinds of
imports are order sensitive:

Relative imports

For instance, sorting the following imports in alphabetical order
introduces compilation errors:

import scala.util
import util.control
import control.NonFatal

I'll keep this ticket open for measuring appetite and help other people that run into this limitation. However, at the moment there is no plan to lift that limitation, as it's a non-trivial fix. PRs are welcome though!

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

No branches or pull requests

2 participants