Skip to content

OrganizeImports rule can break compilation #2006

Open
@satorg

Description

@satorg

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:

  1. Do not push import io.whatever below import fs2._ if the latter already contains io. E.g., the following imports sections:
    import gg.hh.ii._
    import io.circe._
    import aa.bb.cc._
    import fs2._
    could be re-arranged this way in such a case:
    import aa.bb.cc._
    import io.circe._
    import fs2._
    import gg.hh.ii._
  2. Prefix conflicting imports with _root_.

I think, these two approaches can be made configurable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions