From 532e91504bb38577c8062300b87110b12220c49e Mon Sep 17 00:00:00 2001 From: Scala Steward <43047562+scala-steward@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:06:09 +0100 Subject: [PATCH] Update sbt-scalafix to 0.13.0 (#5506) Co-authored-by: Michel Davit --- project/plugins.sbt | 2 +- scalafix/project/plugins.sbt | 2 +- .../main/scala/fix/v0_14_0/FixAvroCoder.scala | 27 ++++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 846d1510b2..b7101cca53 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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") diff --git a/scalafix/project/plugins.sbt b/scalafix/project/plugins.sbt index 5390f1a7c2..ed2fa9fc47 100644 --- a/scalafix/project/plugins.sbt +++ b/scalafix/project/plugins.sbt @@ -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") diff --git a/scalafix/rules/src/main/scala/fix/v0_14_0/FixAvroCoder.scala b/scalafix/rules/src/main/scala/fix/v0_14_0/FixAvroCoder.scala index 2a4c873caa..fb7324c1c4 100644 --- a/scalafix/rules/src/main/scala/fix/v0_14_0/FixAvroCoder.scala +++ b/scalafix/rules/src/main/scala/fix/v0_14_0/FixAvroCoder.scala @@ -185,6 +185,7 @@ object FixAvroCoder { } class FixAvroCoder extends SemanticRule("FixAvroCoder") { + import FixAvroCoder._ override def fix(implicit doc: SemanticDocument): Patch = { @@ -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 } }