question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OrganizeImports produces non-sensical imports

See original GitHub issue

OrganizeImports 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:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lianchengcommented, Dec 2, 2020

@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.

0reactions
sideeffffectcommented, Dec 2, 2020

I’ve tried to run it again on the same snapshot with both 0.4.2 and 0.4.4, and fix 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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Organize Imports broken in 1.73.0 · Issue #165326 - GitHub
Type: Bug After upgrading VSCode to 1.73.0, the Organize Imports action hangs indefinitely, preventing the editor from closing gracefully.
Read more >
194358 – [import rewrite] Organize Imports produces wrong ...
It starts with the list of known groups defined in the organize import preferences, then adds packages to their respective groups. All "type...
Read more >
Organize files while importing
In Final Cut Pro, choose how to organize your media when you import it. Choose an event, specify where files are stored, add...
Read more >
How to config VSCode's Organize Imports order?
The built-in "Organize Imports" functionality has no configuration, according to the documentation. You can customize import ordering using ...
Read more >
dart: enabling "Optimize imports on Save" produces invalid ...
dart: enabling "Optimize imports on Save" produces invalid code if Flutter "Organize imports on Save" is enabled · ensure "Reformat code" and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found