scalacenter / scalafix

Refactoring and linting tool for Scala

Home Page:https://scalacenter.github.io/scalafix/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OrganizeImports: unexpected ordering of relative imports

jumale opened this issue · comments

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:

  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: