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: unexpected ordering of relative imports #1796

Open
jumale opened this issue Jun 22, 2023 · 1 comment
Open

OrganizeImports: unexpected ordering of relative imports #1796

jumale opened this issue Jun 22, 2023 · 1 comment

Comments

@jumale
Copy link

jumale commented Jun 22, 2023

scalafix version 0.11.0 (built in OrganizeImports)

Relative imports are still reordered even if using importsOrder = Keep.
Having this config:

rules = [
  OrganizeImports
]

OrganizeImports {
  removeUnused = true
  groups = ["*"]
  blankLines = Manual
  groupedImports = Keep
  importSelectorsOrder = Keep
  importsOrder = Keep
}

and this code:

package com.example

import Foo._
import java.time.Instant
import java.util.UUID

class Foo {
  println(a)
}

object Foo {
  val a: Instant = ???
  val b: UUID    = ???
}

after scalafixAll the imported Foo._ gets unexpectedly reordered like this:

import java.time.Instant
import java.util.UUID
import Foo._

However it does not change the order, if the import is fully prefixed:

import com.example.Foo._ // <- won't be reordered
import java.time.Instant
import java.util.UUID
@bjaglin
Copy link
Collaborator

bjaglin commented Jul 19, 2023

Hi @jumale, thanks for the report!

There is currently a specific behavior for relative imports described in the docs:

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.
  2. ...

Does your use-case involve relative imports when there are in the same file/package or is that just to make the bug report easy? We might be able to make an exception for imports relatives to the source package.

I won't have bandwidth to look at it, but if you want to have a look at it, here are some pointers:

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