Skip to content

Commit 2ca0d85

Browse files
authored
Merge pull request #1992 from bjaglin/doc-removeunused
improve docs about RemoveUnused
2 parents b5230fd + b6f35b3 commit 2ca0d85

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

docs/rules/RemoveUnused.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,22 @@ You may request more granular warnings to the compiler if you opt-out
132132
from some rewrites in the rule configuration.
133133

134134
```
135-
$ scala212 -Wunused:help
135+
$ scala212 -Ywarn-unused:help
136+
Enable or disable specific `unused' warnings
137+
imports Warn if an import selector is not referenced.
138+
patvars Warn if a variable bound in a pattern is unused.
139+
privates Warn if a private member is unused.
140+
locals Warn if a local definition is unused.
141+
explicits Warn if an explicit parameter is unused.
142+
implicits Warn if an implicit parameter is unused.
143+
nowarn Warn if a @nowarn annotation does not suppress any warnings.
144+
params Enable -Ywarn-unused:explicits,implicits.
145+
linted -Xlint:unused.
146+
Default: All choices are enabled by default.
147+
```
148+
149+
```
150+
$ scala213 -Wunused:help
136151
Enable or disable specific `unused` warnings
137152
imports Warn if an import selector is not referenced.
138153
patvars Warn if a variable bound in a pattern is unused.

docs/users/installation.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -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
6666
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) ...
6969
```
7070

7171
The first error message means the
7272
[SemanticDB](https://scalameta.org/docs/semanticdb/guide.html) compiler plugin
7373
is not enabled for this project. The second error says `RemoveUnused` requires
7474

7575
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`
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

scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ object OrganizeImports {
916916
Configured.error(
917917
"A Scala compiler option is required to use OrganizeImports with"
918918
+ " \"OrganizeImports.removeUnused\" set to true. To fix this problem, update your"
919-
+ " build to add `-Ywarn-unused` (2.12) or `-Wunused:imports` (2.13 and 3.4+)."
919+
+ " build to add `-Ywarn-unused-import` (2.12) or `-Wunused:imports` (2.13 and 3.4+)."
920920
)
921921
else
922922
Configured.error(

0 commit comments

Comments
 (0)