@@ -62,18 +62,18 @@ Next, if we run another rule like `RemoveUnused` then we get an error
62
62
```
63
63
> myproject/scalafix RemoveUnused
64
64
[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
66
66
rules 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) ...
69
69
```
70
70
71
71
The first error message means the
72
72
[ SemanticDB] ( https://scalameta.org/docs/semanticdb/guide.html ) compiler plugin
73
73
is not enabled for this project. The second error says ` RemoveUnused ` requires
74
74
75
75
the 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 `
77
77
78
78
``` diff
79
79
/*
@@ -90,7 +90,12 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in
90
90
)
91
91
92
92
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
+ + }
94
99
)
95
100
```
96
101
@@ -104,7 +109,12 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in
104
109
scalaVersion := "@SCALA212@", // @SCALA213@, or 3.x
105
110
+ semanticdbEnabled := true, // enable SemanticDB
106
111
+ 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
+ + }
108
118
)
109
119
```
110
120
0 commit comments