OrganizeImports produces non-sensical imports
See original GitHub issueOrganizeImports produced non-sensical imports, like
// test-tests/shared/src/test/scala/zio/test/environment/RandomSpec.scala
import scala.util.Random.random.Random
// test/shared/src/main/scala/zio/test/package.scala
import zio.test.PlatformSpecific.TestEnvironment.collection.immutable.SortedSet
...
import scala.collection.immutable.SortedSet.duration.Duration
Discovered in PR https://github.com/zio/zio/pull/4449/
Full commit with all the changes OrganizeImports made is here: https://github.com/zio/zio/pull/4449/commits/495623ed9168a0646ecd5ef73526a43ad8d986ac
These non-sensical imports had to be manually fixed by this commit https://github.com/zio/zio/pull/4449/commits/689c20576eeb156c972addff4b0141182b1fd883
The original snapshot of the codebase is here https://github.com/zio/zio/tree/1816c4232ee16f8e50ef4291b7810ebdea4e8529 + you have to adjust the OrganizeImports settings to
OrganizeImports {
expandRelative = true
groupedImports = Merge
# IntelliJ IDEA's order so that they don't fight each other
groups = [
"java."
"*"
"scala."
]
}
RemoveUnused {
imports = false // handled by OrganizeImports
}
It should be 100% reproducible, just run fix
from sbt
The version of OrganizeImports used is 0.4.4 https://github.com/zio/zio/blob/1816c4232ee16f8e50ef4291b7810ebdea4e8529/project/BuildHelper.scala#L236
Are there any other details that would help you debug this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@sideeffffect, thanks for the follow-up! Using ZIO as a stress test is a great idea. I did want to add a few automated tests to check out certain repos and run
OrganizeImports
against them for correctness test and maybe also perf tests.Unfortunately, I don’t have enough cycles recently, but will try to find some time to root cause this issue later.
I’ve tried to run it again on the same snapshot with both
0.4.2
and0.4.4
, andfix
finished with different outcomes. OrganizeImports always produced nonsensical imports in different two files. It indeed seems like some weird interaction between Scalafix rules.It’s not a huge deal, it’s easy to fix manually, because it’s only in few files. But it still would be great to get to the bottom of the problem. Perhaps you could use ZIO as a stress test for OrganizeImports, but you’ll have to give sbt a lot of memory (as I’ve shown above).