I believe my source code files feature many imports that are not used in the code (as I have a bad habit of copying them from existing to new files). When coding C# in Visual Studio (or, maybe, it's a feature of an add-on of it) one can wipe out all the unused imports in just a click. Is there an analogous tool for Scala? Would be cool if I could just point it to my sources directory and it would clean all the files inside it and all its subdirs and subdirs of them (etc).
IntelliJ can automatically clean up imports, not just highlight them, and for the whole directory. The shortcut is Ctrl + Alt + O
.
I think Intellij marks unused imports gray. I don't think there is an automatic tool yet. Eclipse's and ensime's "organize imports" refactoring doesn't remove imports. You could of course always comment out individual imports and recompile.
Scalafix has a rewrite to remove unused imports: https://scalacenter.github.io/scalafix/#RemoveUnusedImports
add addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.0-M1")
to your project/plugins.sbt
then run sbt "scalafix RemoveUnusedImports"
来源:https://stackoverflow.com/questions/7767567/is-there-a-tool-for-scala-to-clean-all-the-unused-imports-from-all-the-code-file