@@ -62,18 +62,18 @@ Next, if we run another rule like `RemoveUnused` then we get an error
6262```
6363> myproject/scalafix RemoveUnused
6464[error] (Compile / scalafix) scalafix.sbt.InvalidArgument: 2 errors
65- [E1] The semanticdb- scalac compiler plugin is required to run semantic
65+ [E1] The scalac compiler should produce semanticdb files to run semantic
6666rules like RemoveUnused ...
67- [E2] The Scala compiler option "-Ywarn-unused" is required to use
68- RemoveUnused ...
67+ [E2] A Scala compiler option is required to use RemoveUnused. To fix this
68+ problem, update your build to add -Ywarn-unused-import (with 2.12) ...
6969```
7070
7171The first error message means the
7272[ SemanticDB] ( https://scalameta.org/docs/semanticdb/guide.html ) compiler plugin
7373is not enabled for this project. The second error says ` RemoveUnused ` requires
7474
7575the Scala compiler option ` -Ywarn-unused-import ` (or ` -Wunused:imports ` in
76- 2.13.x). To fix both problems, add the following settings to ` build.sbt `
76+ 2.13.x or 3.x ). To fix both problems, add the following settings to ` build.sbt `
7777
7878``` diff
7979 /*
@@ -90,7 +90,12 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in
9090 )
9191
9292 lazy val myproject = project.settings(
93- scalacOptions += "-Ywarn-unused-import" // required by `RemoveUnused` rule
93+ + scalacOptions += {
94+ + if (scalaVersion.value.startsWith("2.12"))
95+ + "-Ywarn-unused-import"
96+ + else
97+ + "-Wunused:imports"
98+ + }
9499 )
95100```
96101
@@ -104,7 +109,12 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in
104109 scalaVersion := "@SCALA212@", // @SCALA213@, or 3.x
105110+ semanticdbEnabled := true, // enable SemanticDB
106111+ semanticdbVersion := scalafixSemanticdb.revision, // only required for Scala 2.x
107- + scalacOptions += "-Ywarn-unused-import" // Scala 2.x only, required by `RemoveUnused`
112+ + scalacOptions += {
113+ + if (scalaVersion.value.startsWith("2.12"))
114+ + "-Ywarn-unused-import"
115+ + else
116+ + "-Wunused:imports"
117+ + }
108118 )
109119```
110120
0 commit comments