Skip to content

Commit 17c10f8

Browse files
Update Scalafix migration to handle explicit imports from the plugin autoImport object
1 parent 14d7ed9 commit 17c10f8

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ lazy val `sbt-tpolecat-scalafix` = scalafixProject("sbt-tpolecat")
6464
)
6565
)
6666
.inputSettings(addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.0"))
67+
.inputConfigure(_.enablePlugins(SbtPlugin))
6768
.outputConfigure(_.dependsOn(`sbt-tpolecat-plugin`))
69+
.outputConfigure(_.enablePlugins(SbtPlugin))

scalafix/input/src/main/scala/org/typelevel/fix/v0_5Tests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ rule = v0_5
55
import io.github.davidgregory084.TpolecatPlugin
66
import io.github.davidgregory084.{ScalaVersion => Version}
77
import io.github.davidgregory084.{DevMode => Dev}
8+
import io.github.davidgregory084.TpolecatPlugin.autoImport._
9+
import io.github.davidgregory084.TpolecatPlugin.autoImport.{ tpolecatCiModeEnvVar, scalacOptionsFor }
810
import io.github.davidgregory084._
911
import _root_.io.github.davidgregory084.ScalacOption
1012
import _root_.io.github.davidgregory084._

scalafix/output/src/main/scala/org/typelevel/fix/v0_5Tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// format: off
22
import org.typelevel.sbt.tpolecat.{ DevMode => Dev, TpolecatPlugin, _ }
3+
import org.typelevel.sbt.tpolecat.TpolecatPlugin.autoImport.{ scalacOptionsFor, tpolecatCiModeEnvVar, _ }
34
import org.typelevel.scalacoptions.{ ScalaVersion => Version, ScalacOption, _ }
45
// format: on
56

scalafix/rules/src/main/scala/fix/v0_5.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class v0_5 extends SemanticRule("v0_5") {
4040

4141
val ScalacOptionsSym = JavaMajorVersionSym + ScalacOptionSym + ScalaVersionSym
4242

43+
// autoImport contents
44+
val TpolecatPluginAutoImportSym =
45+
SymbolMatcher.exact("io/github/davidgregory084/TpolecatPlugin.autoImport.")
46+
4347
private def makeSelector(packages: String*): Term.Ref =
4448
packages.tail.foldLeft(Term.Name(packages.head): Term.Ref) { case (selector, pkg) =>
4549
Term.Select(selector, Term.Name(pkg))
@@ -50,6 +54,14 @@ class v0_5 extends SemanticRule("v0_5") {
5054
Importer(makeSelector("org", "typelevel", "sbt", "tpolecat"), List(importee))
5155
)
5256

57+
private def makeAutoImportObjectImport(importee: Importee) =
58+
Patch.addGlobalImport(
59+
Importer(
60+
makeSelector("org", "typelevel", "sbt", "tpolecat", "TpolecatPlugin", "autoImport"),
61+
List(importee)
62+
)
63+
)
64+
5365
private def makeScalacOptionsImport(importee: Importee) =
5466
Patch.addGlobalImport(
5567
Importer(makeSelector("org", "typelevel", "scalacoptions"), List(importee))
@@ -72,5 +84,14 @@ class v0_5 extends SemanticRule("v0_5") {
7284
makeScalacOptionsImport(importee) +
7385
Patch.removeImportee(importee)
7486
}.asPatch
87+
case importer @ Importer(ref, importees) if TpolecatPluginAutoImportSym.matches(ref) =>
88+
importees.collect {
89+
case importee @ Importee.Name(name) =>
90+
makeAutoImportObjectImport(importee) + Patch.removeImportee(importee)
91+
case rename @ Importee.Rename(name, _) =>
92+
makeAutoImportObjectImport(rename) + Patch.removeImportee(rename)
93+
case importee @ Importee.Wildcard() =>
94+
makeAutoImportObjectImport(importee) + Patch.removeImportee(importee)
95+
}.asPatch
7596
}.asPatch
7697
}

0 commit comments

Comments
 (0)