Skip to content

Commit

Permalink
Update sbt-scalafix to 0.13.0 (#5506)
Browse files Browse the repository at this point in the history
Co-authored-by: Michel Davit <[email protected]>
  • Loading branch information
scala-steward and RustedBones authored Dec 19, 2024
1 parent 4d701c1 commit 532e915
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
addDependencyTreePlugin
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.7.3")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.2.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0")
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1")
Expand Down
2 changes: 1 addition & 1 deletion scalafix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
27 changes: 17 additions & 10 deletions scalafix/rules/src/main/scala/fix/v0_14_0/FixAvroCoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ object FixAvroCoder {
}

class FixAvroCoder extends SemanticRule("FixAvroCoder") {

import FixAvroCoder._

override def fix(implicit doc: SemanticDocument): Patch = {
Expand Down Expand Up @@ -233,29 +234,35 @@ class FixAvroCoder extends SemanticRule("FixAvroCoder") {
}
}
.foldLeft(false)(_ || _)
val avroValuePatch = if (usesAvroCoders) Patch.addGlobalImport(avroImport) else Patch.empty

val patches = doc.tree.collect {
val importPatches = doc.tree.collect {
case importer"com.spotify.scio.coders.Coder.{..$imps}" =>
// fix direct import from Coder
imps.collect {
case i @ (importee"avroGenericRecordCoder" | importee"avroSpecificRecordCoder" |
importee"avroSpecificFixedCoder") =>
Patch.removeImportee(i) + Patch.addGlobalImport(avroImport)
Patch.removeImportee(i)
}.asPatch
case importer"com.spotify.scio.avro.{..$imps}" =>
imps
.filterNot {
case importee"_" => true
case _ => false
}
.map(i => Patch.removeImportee(i) + Patch.addGlobalImport(avroImport))
.filterNot(_.isInstanceOf[Importee.Wildcard])
.map(Patch.removeImportee)
.asPatch
case t @ q"$obj.$fn" if AvroCoderMatcher.matches(fn.symbol) =>
// fix direct usage of Coder.avro*
Patch.replaceTree(t, q"$fn".syntax) + Patch.addGlobalImport(avroImport)
Patch.replaceTree(t, q"$fn".syntax)
}.asPatch

patches + avroValuePatch
val importWildcardPatch = {
val hasAvroWildcardImport = doc.tree
.collect { case importer"com.spotify.scio.avro.{..$imps}" =>
imps.exists(_.isInstanceOf[Importee.Wildcard])
}
.foldLeft(false)(_ || _)
if (hasAvroWildcardImport) Patch.empty else Patch.addGlobalImport(avroImport)
}

if (usesAvroCoders || importPatches.nonEmpty) importPatches + importWildcardPatch
else Patch.empty
}
}

0 comments on commit 532e915

Please sign in to comment.