scalafix
scalafix copied to clipboard
OrganizeImports: unexpected ordering of relative imports
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
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:
- The expandRelative option is set to false and there are relative imports.
- ...
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:
- input/output test cases
- logic to identify relative imports in order to segregate them