Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoveUnused does not clean Scala 3 style wildcard import with -Xsource:3 #1663

Closed
xuwei-k opened this issue Aug 31, 2022 · 2 comments · Fixed by #1664
Closed

RemoveUnused does not clean Scala 3 style wildcard import with -Xsource:3 #1663

xuwei-k opened this issue Aug 31, 2022 · 2 comments · Fixed by #1664

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Aug 31, 2022

step

build.sbt

scalaVersion := "2.13.8"

semanticdbEnabled := true

scalacOptions ++= Seq("-Wunused", "-Xsource:3")

project/build.properties

sbt.version=1.7.1

project/plugins.sbt

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")

Main.scala

import scala.collection.mutable
import scala.util._
import scala.io.*

object Main

run: sbt "scalafix RemoveUnused"

actual

log

[warn] /Users/kenji/remove-unused-scala-3-syntax/Main.scala:1:25: Unused import
[warn] import scala.collection.mutable
[warn]                         ^
[warn] /Users/kenji/remove-unused-scala-3-syntax/Main.scala:2:19: Unused import
[warn] import scala.util._
[warn]                   ^
[warn] /Users/kenji/remove-unused-scala-3-syntax/Main.scala:3:17: Unused import
[warn] import scala.io.*
[warn]                 ^
[warn] three warnings found
[info] Running scalafix on 1 Scala sources
[success] Total time: 3 s, completed Aug 31, 2022, 4:36:11 AM

diff

@@ -1,5 +1,4 @@
-import scala.collection.mutable
-import scala.util._
+
 import scala.io.*

expect

remove import scala.io.*

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Aug 31, 2022

note: different position if Scala 3 style wildcard 🤔

import scala.io.*
^^^^^^^^^^^^^^^^^
import scala.util._
                  ^
--- a/scalafix-rules/src/main/scala/scalafix/internal/rule/RemoveUnused.scala
+++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/RemoveUnused.scala
@@ -65,6 +65,7 @@ class RemoveUnused(config: RemoveUnusedConfig)
 
     doc.diagnostics.foreach { diagnostic =>
       if (config.imports && diagnostic.message == "Unused import") {
+        println(diagnostic)
         isUnusedImport += diagnostic.position
``

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Aug 31, 2022

case i if isUnusedImport(importPosition(i)) =>

Maybe isUnusedImport(importPosition(i)) return false if Scala 3 style wildcard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant