Is there a tool for Scala to clean all the unused imports from all the code files? [closed]

不羁岁月 提交于 2019-12-05 15:43:12

问题


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


回答1:


IntelliJ can automatically clean up imports, not just highlight them, and for the whole directory. The shortcut is Ctrl + Alt + O.




回答2:


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.




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!