æªä½¿ç¨ã®importãå¤ãæ¤æ»ããã³ã³ãã¤ã©ãªãã·ã§ã³ã¨MetalsãScalafixã¨ã®é¢ä¿ã«ã¤ãã¦èª¿ã¹ãã¡ã¢ã§ããã³ã³ãã¤ã©ã¾ããã®å®è£ ã追ãããã¦ããªãå¯è½æ§ããããããééã£ã¦ããããææããã ããã¨å¬ããã§ãã
ãã¤ã¦Scala 2ç³»ã§ã¯unused importãªã©ã®ãã§ãã¯ã«-Ywarn-unused
ãªã©ã使ã£ã¦ãããScala 3.3.0ã§ã¯ã-Wunused:all
ã使ããã¨ã§æªä½¿ç¨ã®å¤æ°ãã¤ã³ãã¼ãããã§ãã¯ããã
import scala.util.control.Breaks def main():Unit = val x = 42 val y = 43 val z = 44 println(x + z) main()
ãã®ãããªã³ã¼ãã-Wunused:all
ãã¤ãã¦ã³ã³ãã¤ã«ãã¦ã¿ããä¾ãã°Scala CLIã使ã£ã¦å®è¡ãã¦ã¿ããScala CLIã§ã¯ã-O
ãªãã·ã§ã³ã§ã³ã³ãã¤ã©ãªãã·ã§ã³ãæå®ã§ããã
$ scala-cli run -O -Wunused:all unused-check.scala.sc Compiling project (Scala 3.3.0, JVM) [warn] ./unused-check.scala.sc:3:27 [warn] unused import [warn] import scala.util.control.Breaks [warn] ^^^^^^ [warn] ./unused-check.scala.sc:7:7 [warn] unused local definition [warn] val y = 43 [warn] ^ Compiled project (Scala 3.3.0, JVM) 86
ã³ã³ãã¤ã©ãæªä½¿ç¨ã®å¤æ°ã¨ã¤ã³ãã¼ããæ¤åºãã¦ãããã
ã¡ãªã¿ã«æ¤åºããã«ãã´ãªã¯ç´°ããå¶å¾¡ã§ãã-Wunused:all
ã®ä»£ããã«-Wunused:imports
ãªã©ãå©ç¨å¯è½ã ã
-Ywarn-unused
ã¨ã¯
ãã¨ãã¨-Ywarn-unused
ã¯Scala2ç³»ã®ã³ã³ãã¤ã©ãªãã·ã§ã³ã§ããã
ãã®ãªãã·ã§ã³ã¯2.13ããã¯-Wunused
ã¨ãã¦ã使ããæ¨è¨è¼ããã¦ããããæ´å²ççµç·¯ã§-Ywarn-unused
ã§ä½¿ã£ã¦ãã人ãå¤ãã£ãã®ã§ã¯ãªãã ããããScala 3以éã§ã¯-Wunused
ã«çµ±ä¸ããã¦ããã®ã§æ³¨æãããã
lspã®organize-importsã¯ã¾ã åããªã / Scalafixã®å ´å
Scalaã®LSPã¯ã©ã¤ã¢ã³ãã§ããMetalsã¯ãorganize importsãScalafixã«å§è²ãã¦ãããã¤ã¾ããorganize importsãå®è¡ããã¨RemoveUnusedã«ã¼ã«ãimportéå®ã§åä½ããã¨ãããã¨ã
ãã®æ©è½ã¯å²ã¨æè¿è¿½å ããã¦ãã¨ã¦ãå¬ããæ©è½ã ããã ãRemoveUnusedã«ã¼ã«ã®Scala3対å¿ã¯ã¾ã å®è£ ä¸ã§ã¾ã å©ç¨ã§ããªãã
$ scalafix -v 0.11.0 $ scalafix --scala-version 3.3.0 -r RemoveUnused error: This rule is specific to Scala 2, because the compiler option `-Ywarn-unused` is not available yet in scala 3 To fix this error, remove RemoveUnused from .scalafix.conf
ç¾å¨ã¯semanticDBã¾ããã®å®è£ ãè¡ããã¦ããããã ãæ°é·ã«å¾ ã¨ããè¦åèªä½ã¯Scalaã³ã³ãã¤ã©ãåºãã¦ãããã®ã§ãå½åã¯ãããæ´»ç¨ãããã¨ã«ãªãã
è£è¶³: -W
ã¨ã-Y
ã£ã¦ãªã«
Scala2.13ã§ä½¿ããã³ã³ãã¤ã©ãªãã·ã§ã³ã使ãããã©ããã¯ä»¥ä¸ã«ç¤ºããã¼ã¸ã§ç¶²ç¾ ããã¦ãããããç¨åº¦åé¡ããã¦ãã:
ã¾ãå®å ¨ã«æ°ãããªãã·ã§ã³ã¯ä»¥ä¸ã§ç¶²ç¾ ããã¦ãã:
ããã«ããã°ã-W
ã¯Warning optionsã¨ããã«ãã´ãªã®ã³ã³ãã¤ã©ãªãã·ã§ã³ã§ãããã¨ãããããè¦åãå¸ããªãã·ã§ã³ã¨ããããã
ã»ãã«ãã-X
ã¯Advanced settingsã¨ããã«ãã´ãªã«å
¥ãã-Y
ã¯Private settingsã¨ããã«ãã´ãªã§ããã主ã«ã³ã³ãã¤ã©éçºåãã®ãã¾ãå®å®ãã¦ããªãï¼ãªãã·ã§ã³ã並ãã§ããããããã¨ããããã
åèæç®
ãã®æ©è½ã¯3.3.0-RC2ããå©ç¨å¯è½ã«ãªã£ã¦ããããã ã