Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 971
Ivan Avatar asked Oct 14 '11 12:10

Ivan


People also ask

How do I automatically delete unused imports?

please use the default key combination below. CTRL + ALT + O ---> to remove the unused imports in windows. However, you can also change the keymap of "Optimize Imports" in settings.

How do you organize imports in VS code?

In VSCode, go to File -> Preferences -> Settings and click on the icon in the top right hand corner to open up the settings in JSON. Et voilà! Your imports will now be organized every time you save a file.


2 Answers

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

enter image description here

like image 61
Luigi Plinge Avatar answered Oct 20 '22 08:10

Luigi Plinge


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"

like image 34
Guillaume Massé Avatar answered Oct 20 '22 08:10

Guillaume Massé