scalafix
scalafix copied to clipboard
`OrganizeImports` rule can break compilation
Actual Behavior
A real example. Consider a project with the following two dependencies:
Also consider a scala file with the following imports section:
import io.circe._
import fs2._
After applying the OrganizeImports
rule the section will be simply re-arranged:
import fs2._
import io.circe._
Which breaks the compilation, because there's io
sub-package inside fs2
and therefore the compiler will be assuming that we're trying to import fs2.io.circe._
at the second line.
Expected Behavior
I can think of two strategies of how it could be mitigated:
- Do not push
import io.whatever
belowimport fs2._
if the latter already containsio
. E.g., the following imports sections:
could be re-arranged this way in such a case:import gg.hh.ii._ import io.circe._ import aa.bb.cc._ import fs2._
import aa.bb.cc._ import io.circe._ import fs2._ import gg.hh.ii._
- Prefix conflicting imports with
_root_.
I think, these two approaches can be made configurable.