Skip to content

Commit 44e5394

Browse files
committed
support RemoveUnused on Scala 3.3.0
1 parent 9fa948a commit 44e5394

20 files changed

+21
-41
lines changed

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ lazy val testsInput = projectMatrix
178178
noPublishAndNoMima,
179179
scalacOptions ~= (_.filterNot(_ == "-Yno-adapted-args")),
180180
scalacOptions ++= warnAdaptedArgs.value, // For NoAutoTupling
181-
scalacOptions ++= warnUnusedImports.value, // For RemoveUnused
182-
scalacOptions ++= warnUnused.value, // For RemoveUnusedTerms
181+
scalacOptions += "Wunused", // For RemoveUnusedTerms
183182
logLevel := Level.Error, // avoid flood of compiler warnings
184183
libraryDependencies ++= testsDependencies.value,
185184
coverageEnabled := false

docs/rules/RemoveUnused.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ example diff from running `sbt "scalafix RemoveUnused"`.
1414

1515
To use this rule:
1616

17-
- Enable the Scala compiler option `-Ywarn-unused` (or `-Wunused` in 2.13). In
18-
sbt, this is done with `scalacOptions += "-Ywarn-unused"`.
17+
- Enable the Scala compiler option `-Wunused`. In sbt, this is done with
18+
`scalacOptions += "-Wunused"`.
1919
- Disable `-Xfatal-warnings` if you have it enabled. This is required so the
2020
compiler warnings do not fail the build before running Scalafix. If you are
2121
running 2.13.2 or later, you may keep `-Xfatal-warnings` by modifying how
2222
specific warnings are handled via `scalacOptions += "-Wconf:cat=unused:info"`.
23-
- This rule **can't work** yet on Scala 3 projects since the compiler option `warn-unused`
24-
is not yet available in Scala 3. You need to remove `RemoveUnused`
25-
from `.scalafix.conf` for Scala 3 projects.
2623

2724
## Examples
2825

@@ -146,4 +143,4 @@ Enable or disable specific `unused' warnings
146143
params Enable -Ywarn-unused:explicits,implicits.
147144
linted -Xlint:unused.
148145
Default: All choices are enabled by default.
149-
```
146+
```

project/Dependencies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scala.util.Try
99
object Dependencies {
1010
val scala212 = "2.12.17"
1111
val scala213 = "2.13.10"
12-
val scala3 = "3.2.2"
12+
val scala3 = "3.3.0-RC5"
1313

1414
val buildScalaVersions = Seq(scala212, scala213, scala3)
1515
val testTargetScalaVersions = Seq(scala212, scala213, scala3)

project/ScalafixBuild.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
4646
scalaVersion.value.startsWith("2.12")
4747
}
4848
lazy val warnUnusedImports = Def.setting {
49-
if (isScala3.value) Nil
50-
else if (isScala213.value) Seq("-Wunused:imports")
49+
if (isScala213.value || isScala3.value) Seq("-Wunused:imports")
5150
else Seq("-Ywarn-unused-import")
5251
}
53-
lazy val warnUnused = Def.setting {
54-
if (isScala2.value) Seq("-Ywarn-unused")
55-
else Nil
56-
}
5752
lazy val targetJvm = Def.setting {
5853
if (isScala3.value) Seq("-Xtarget:8")
5954
else if (isScala213.value) Seq("-release", "8")

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class RemoveUnused(config: RemoveUnusedConfig)
2626
def this() = this(RemoveUnusedConfig.default)
2727

2828
override def description: String =
29-
"Removes unused imports and terms that reported by the compiler under -Ywarn-unused"
29+
"Removes unused imports and terms that reported by the compiler under -Yunused"
3030
override def isRewrite: Boolean = true
3131

3232
private def warnUnusedPrefix = List("-Wunused", "-Ywarn-unused")
@@ -36,17 +36,18 @@ class RemoveUnused(config: RemoveUnusedConfig)
3636
warnUnusedPrefix.exists(prefix => option.startsWith(prefix)) ||
3737
warnUnusedString.contains(option)
3838
)
39-
if (config.scalaVersion.startsWith("3"))
40-
Configured.error(
41-
"This rule is specific to Scala 2, because the compiler option `-Ywarn-unused` is not available yet in scala 3 " +
42-
"To fix this error, remove RemoveUnused from .scalafix.conf"
43-
)
44-
else if (!hasWarnUnused) {
45-
Configured.error(
46-
s"""|The Scala compiler option "-Ywarn-unused" is required to use RemoveUnused.
47-
|To fix this problem, update your build to use at least one Scala compiler
48-
|option like -Ywarn-unused, -Xlint:unused (2.12.2 or above), or -Wunused (2.13 only)""".stripMargin
49-
)
39+
if (!hasWarnUnused) {
40+
if (config.scalaVersion.startsWith("3"))
41+
Configured.error(
42+
"""|The Scala compiler option "-Ywarn-unused" (available from Scala 3.3.0-RC2) is
43+
|required to use RemoveUnused. To fix this problem, update your build to add it.""".stripMargin
44+
)
45+
else
46+
Configured.error(
47+
"""|A Scala compiler option is required to use RemoveUnused. To fix this problem,
48+
|update your build to add either -Ywarn-unused, -Xlint:unused (2.12.2 or above),
49+
|or -Wunused (2.13).""".stripMargin
50+
)
5051
} else {
5152
config.conf
5253
.getOrElse("RemoveUnused")(this.config)

scalafix-tests/input/src/main/scala-2.13/test/removeUnused/RemoveUnusedParams.scala

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)