From 195cefbde03529155c7d4f2036d9349b87d9cafb Mon Sep 17 00:00:00 2001 From: "Frank S. Thomas" Date: Sat, 22 Jun 2019 21:45:53 +0200 Subject: [PATCH 1/2] Update sbt-scalafix to 0.6.0-M9 --- scalafix/build.sbt | 31 +++++++++++-------- scalafix/project/build.properties | 2 +- scalafix/project/plugins.sbt | 3 +- .../src/main/scala/fix/Cats_v1_0_0.scala | 3 +- .../tests/src/test/scala/fix/Cats_Tests.scala | 8 +---- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/scalafix/build.sbt b/scalafix/build.sbt index 5001f91583..2eefb62ca4 100644 --- a/scalafix/build.sbt +++ b/scalafix/build.sbt @@ -1,13 +1,21 @@ -// Use a scala version supported by Scalafix. val V = _root_.scalafix.Versions -scalaVersion in ThisBuild := V.scala212 + +inThisBuild( + List( + scalaVersion in ThisBuild := V.scala212, + addCompilerPlugin(scalafixSemanticdb), + scalacOptions += "-Yrangepos" + )) lazy val rules = project.settings( libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.version ) lazy val input = project.settings( - scalafixSourceroot := sourceDirectory.in(Compile).value, + scalacOptions += { + val sourceroot = sourceDirectory.in(Compile).value / "scala" + s"-P:semanticdb:sourceroot:$sourceroot" + }, libraryDependencies ++= Seq( "org.typelevel" %% "cats" % "0.9.0" ), @@ -25,15 +33,12 @@ lazy val output = project.settings( lazy val tests = project .settings( libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.version % Test cross CrossVersion.full, - buildInfoPackage := "fix", - buildInfoKeys := Seq[BuildInfoKey]( - "inputSourceroot" -> - sourceDirectory.in(input, Compile).value, - "outputSourceroot" -> - sourceDirectory.in(output, Compile).value, - "inputClassdirectory" -> - classDirectory.in(input, Compile).value - ) + scalafixTestkitOutputSourceDirectories := + sourceDirectories.in(output, Compile).value, + scalafixTestkitInputSourceDirectories := + sourceDirectories.in(input, Compile).value, + scalafixTestkitInputClasspath := + fullClasspath.in(input, Compile).value ) .dependsOn(input, rules) - .enablePlugins(BuildInfoPlugin) + .enablePlugins(ScalafixTestkitPlugin) diff --git a/scalafix/project/build.properties b/scalafix/project/build.properties index c091b86ca4..c0bab04941 100644 --- a/scalafix/project/build.properties +++ b/scalafix/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.16 +sbt.version=1.2.8 diff --git a/scalafix/project/plugins.sbt b/scalafix/project/plugins.sbt index fbbe6c7f91..fa65d52bf3 100644 --- a/scalafix/project/plugins.sbt +++ b/scalafix/project/plugins.sbt @@ -1,4 +1,3 @@ -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.2") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.6.0-M9") addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.2") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0") addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2") diff --git a/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala b/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala index 814b60f8dd..0a0dc1e5cc 100644 --- a/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala +++ b/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala @@ -1,9 +1,8 @@ package fix package v1_0_0 -import scalafix._ +import scalafix.v0._ import scalafix.syntax._ -import scalafix.util.SymbolMatcher import scala.meta._ import scala.meta.contrib._ diff --git a/scalafix/tests/src/test/scala/fix/Cats_Tests.scala b/scalafix/tests/src/test/scala/fix/Cats_Tests.scala index e8e9d338d8..47ba001b89 100644 --- a/scalafix/tests/src/test/scala/fix/Cats_Tests.scala +++ b/scalafix/tests/src/test/scala/fix/Cats_Tests.scala @@ -1,13 +1,7 @@ package fix -import scala.meta._ import scalafix.testkit._ -class Cats_Tests - extends SemanticRuleSuite( - Database.load(Classpath(AbsolutePath(BuildInfo.inputClassdirectory))), - AbsolutePath(BuildInfo.inputSourceroot), - Seq(AbsolutePath(BuildInfo.outputSourceroot)) - ) { +class Cats_Tests extends SemanticRuleSuite() { runAllTests() } From 81cd25c1780a6f197ee5e58a7b6a36db1d315e8c Mon Sep 17 00:00:00 2001 From: "Frank S. Thomas" Date: Sun, 23 Jun 2019 00:43:52 +0200 Subject: [PATCH 2/2] Update sbt-scalafix to 0.9.5 --- scalafix/build.sbt | 12 +-- scalafix/project/plugins.sbt | 2 +- .../src/main/scala/fix/Cats_v1_0_0.scala | 98 +++++++++---------- 3 files changed, 55 insertions(+), 57 deletions(-) diff --git a/scalafix/build.sbt b/scalafix/build.sbt index 2eefb62ca4..1912d51ba0 100644 --- a/scalafix/build.sbt +++ b/scalafix/build.sbt @@ -1,4 +1,4 @@ -val V = _root_.scalafix.Versions +val V = _root_.scalafix.sbt.BuildInfo inThisBuild( List( @@ -8,14 +8,10 @@ inThisBuild( )) lazy val rules = project.settings( - libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.version + libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % V.scalafixVersion ) lazy val input = project.settings( - scalacOptions += { - val sourceroot = sourceDirectory.in(Compile).value / "scala" - s"-P:semanticdb:sourceroot:$sourceroot" - }, libraryDependencies ++= Seq( "org.typelevel" %% "cats" % "0.9.0" ), @@ -32,7 +28,9 @@ lazy val output = project.settings( lazy val tests = project .settings( - libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.version % Test cross CrossVersion.full, + libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full, + compile.in(Compile) := + compile.in(Compile).dependsOn(compile.in(input, Compile)).value, scalafixTestkitOutputSourceDirectories := sourceDirectories.in(output, Compile).value, scalafixTestkitInputSourceDirectories := diff --git a/scalafix/project/plugins.sbt b/scalafix/project/plugins.sbt index fa65d52bf3..acbf579ed2 100644 --- a/scalafix/project/plugins.sbt +++ b/scalafix/project/plugins.sbt @@ -1,3 +1,3 @@ -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.6.0-M9") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5") addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.2") addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2") diff --git a/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala b/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala index 0a0dc1e5cc..c3e4df1805 100644 --- a/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala +++ b/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala @@ -11,22 +11,22 @@ case class RemoveCartesianBuilder(index: SemanticdbIndex) extends SemanticRule(index, "RemoveCartesianBuilder") { private[this] val cartesianBuilders = SymbolMatcher.normalized( - Symbol("_root_.cats.syntax.CartesianOps.`|@|`.") :: + Symbol("cats/syntax/CartesianOps#`|@|`().") :: (1 to 22).toList.map(arity => Symbol( - s"_root_.cats.syntax.CartesianBuilder.CartesianBuilder$arity.`|@|`.")): _* + s"cats/syntax/CartesianBuilder#CartesianBuilder$arity#`|@|`().")): _* ) private[this] val partialApplies = SymbolMatcher.normalized( - Symbol(s"_root_.cats.syntax.CartesianOps.`*>`."), - Symbol(s"_root_.cats.syntax.CartesianOps.`<*`.") + Symbol(s"cats/syntax/CartesianOps#`*>`()."), + Symbol(s"cats/syntax/CartesianOps#`<*`().") ) private[this] val renames: Map[String, String] = (1 to 22).flatMap { arity => Seq( - s"_root_.cats.syntax.CartesianBuilder.CartesianBuilder$arity.map." -> "mapN", - s"_root_.cats.syntax.CartesianBuilder.CartesianBuilder$arity.imap." -> "imapN", - s"_root_.cats.syntax.CartesianBuilder.CartesianBuilder$arity.contramap." -> "contramapN" + s"cats/syntax/CartesianBuilder#CartesianBuilder$arity#map()." -> "mapN", + s"cats/syntax/CartesianBuilder#CartesianBuilder$arity#imap()." -> "imapN", + s"cats/syntax/CartesianBuilder#CartesianBuilder$arity#contramap()." -> "contramapN" ) }.toMap @@ -79,9 +79,9 @@ case class ContraMapToLMap(index: SemanticdbIndex) override def fix(ctx: RuleCtx): Patch = { - val contraMatcher = SymbolMatcher.normalized(Symbol("_root_.cats.functor.Contravariant.Ops.`contramap`.")) + val contraMatcher = SymbolMatcher.normalized(Symbol("cats/functor/Contravariant.Ops#contramap().")) - val unApplyName = "catsUnapply2left" + val unApplyName = "catsSyntaxUContravariant" ctx.tree.collect { case Term.Apply(Term.Select(f, contraMatcher(contramap)), _) if f.denotation.exists(_.name == unApplyName) => @@ -95,14 +95,14 @@ case class RemoveUnapply(index: SemanticdbIndex) extends SemanticRule(index, "RemoveUnapply") { override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.Traverse.Ops.traverseU." -> "traverse", - "_root_.cats.Foldable.Ops.traverseU_." -> "traverse_", - "_root_.cats.Foldable.traverseU_." -> "traverse_", - "_root_.cats.Traverse.Ops.sequenceU." -> "sequence", - "_root_.cats.Foldable.Ops.sequenceU_." -> "sequence_", - "_root_.cats.Foldable.sequenceU_." -> "sequence_", - "_root_.cats.data.Func.appFuncU." -> "appFunc", - "_root_.cats.free.FreeT.liftTU." -> "liftT" + "cats/Traverse.Ops#traverseU()." -> "traverse", + "cats/Foldable.Ops#traverseU_()." -> "traverse_", + "cats/Foldable#traverseU_()." -> "traverse_", + "cats/Traverse.Ops#sequenceU()." -> "sequence", + "cats/Foldable.Ops#sequenceU_()." -> "sequence_", + "cats/Foldable#sequenceU_()." -> "sequence_", + "cats/data/Func.appFuncU()." -> "appFunc", + "cats/free/FreeT.liftTU()." -> "liftT" ) } @@ -111,8 +111,8 @@ case class RenameFreeSuspend(index: SemanticdbIndex) extends SemanticRule(index, "RenameFreeSuspend") { override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.free.Free.suspend." -> "defer", - "_root_.cats.free.TrampolineFunctions.suspend." -> "defer" + "cats/free/Free.suspend()." -> "defer", + "cats/free/TrampolineFunctions#suspend()." -> "defer" ) } @@ -122,12 +122,12 @@ case class RenameReducibleMethods(index: SemanticdbIndex) extends SemanticRule(index, "RenameReducibleMethods") { override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.Reducible.traverse1_." -> "nonEmptyTraverse_", - "_root_.cats.Reducible.Ops.traverse1_." -> "nonEmptyTraverse_", - "_root_.cats.Reducible.intercalate1." -> "nonEmptyIntercalate", - "_root_.cats.Reducible.Ops.intercalate1." -> "nonEmptyIntercalate", - "_root_.cats.Reducible.sequence1_." -> "nonEmptySequence_", - "_root_.cats.Reducible.Ops.sequence1_." -> "nonEmptySequence_" + "cats/Reducible#traverse1_()." -> "nonEmptyTraverse_", + "cats/Reducible.Ops#traverse1_()." -> "nonEmptyTraverse_", + "cats/Reducible#intercalate1()." -> "nonEmptyIntercalate", + "cats/Reducible.Ops#intercalate1()." -> "nonEmptyIntercalate", + "cats/Reducible#sequence1_()." -> "nonEmptySequence_", + "cats/Reducible.Ops#sequence1_()." -> "nonEmptySequence_" ) } @@ -137,10 +137,10 @@ case class SimplifyEitherTLift(index: SemanticdbIndex) extends SemanticRule(index, "SimplifyEitherTLift") { private[this] val leftSymbol = SymbolMatcher.normalized( - Symbol("_root_.cats.data.EitherTFunctions.left.") + Symbol("cats/data/EitherTFunctions/left.") ) private[this] val rightSymbol = SymbolMatcher.normalized( - Symbol("_root_.cats.data.EitherTFunctions.right.") + Symbol("cats/data/EitherTFunctions/right.") ) private[this] def removeWithLeadingComma(ctx: RuleCtx, t: Tree): Patch = @@ -172,9 +172,9 @@ case class RenameInjectProdAndCoproduct(index: SemanticdbIndex) extends SemanticRule(index, "RenameInjectProdAndCoproduct") { override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.free.Inject." -> "_root_.cats.InjectK.", - "_root_.cats.data.Prod." -> "_root_.cats.data.Tuple2K.", - "_root_.cats.data.Coproduct." -> "_root_.cats.data.EitherK." + "cats/free/Inject." -> "cats/InjectK.", + "cats/data/Prod." -> "cats/data/Tuple2K.", + "cats/data/Coproduct." -> "cats/data/EitherK." ) } @@ -187,9 +187,9 @@ case class RenameTupleApplySyntax(index: SemanticdbIndex) ctx.replaceSymbols( (1 to 22).flatMap { arity => Seq( - s"_root_.cats.syntax.Tuple${arity}CartesianOps.map$arity." -> "mapN", - s"_root_.cats.syntax.Tuple${arity}CartesianOps.contramap$arity." -> "contramapN", - s"_root_.cats.syntax.Tuple${arity}CartesianOps.imap$arity." -> "imapN" + s"cats/syntax/Tuple${arity}CartesianOps#map$arity()." -> "mapN", + s"cats/syntax/Tuple${arity}CartesianOps#contramap$arity()." -> "contramapN", + s"cats/syntax/Tuple${arity}CartesianOps#imap$arity()." -> "imapN" ) }: _* ) ++ @@ -206,7 +206,7 @@ case class RemoveSplit(index: SemanticdbIndex) override def fix(ctx: RuleCtx): Patch = { ctx.replaceSymbols( - "_root_.cats.arrow.Split." -> "_root_.cats.arrow.Arrow." + "cats/arrow/Split." -> "cats/arrow/Arrow." ) + ctx.tree.collect { case t @ q"import cats.syntax.split._" => ctx.replaceTree(t, "import cats.syntax.arrow._") @@ -221,7 +221,7 @@ case class RenameEitherTLiftT(index: SemanticdbIndex) override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.data.EitherTFunctions.liftT." -> "liftF" + "cats/data/EitherTFunctions#liftT()." -> "liftF", ) } @@ -232,11 +232,11 @@ case class RenameTransformersLift(index: SemanticdbIndex) override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.data.WriterT.lift." -> "liftF", - "_root_.cats.data.StateT.lift." -> "liftF", - "_root_.cats.data.CommonStateTConstructors.lift." -> "liftF", - "_root_.cats.data.CommonIRWSTConstructors.lift." -> "liftF", - "_root_.cats.data.KleisliFunctions.lift." -> "liftF" + "cats/data/WriterT.lift()." -> "liftF", + "cats/data/StateT.lift()." -> "liftF", + "cats/data/CommonStateTConstructors#lift()." -> "liftF", + "cats/data/CommonIRWSTConstructors#lift()." -> "liftF", + "cats/data/KleisliFunctions#lift()." -> "liftF" ) } @@ -246,14 +246,14 @@ case class RenameApplyApConst(index: SemanticdbIndex) override def fix(ctx: RuleCtx): Patch = ctx.replaceSymbols( - "_root_.cats.Apply.forEffect." -> "productL", - "_root_.cats.Apply.followedBy." -> "productR", - "_root_.cats.Apply.Ops.forEffect." -> "productL", - "_root_.cats.Apply.Ops.followedBy." -> "productR", - "_root_.cats.NonEmptyParallel.parForEffect." -> "parProductL", - "_root_.cats.NonEmptyParallel.parFollowedBy." -> "parProductR", - "_root_.cats.FlatMap.forEffectEval." -> "productLEval", - "_root_.cats.FlatMap.followedByEval." -> "productREval" + "cats/Apply#forEffect()." -> "productL", + "cats/Apply#followedBy()." -> "productR", + "cats/Apply.Ops#forEffect()." -> "productL", + "cats/Apply.Ops#followedBy()." -> "productR", + "cats/NonEmptyParallel#parForEffect()." -> "parProductL", + "cats/NonEmptyParallel#parFollowedBy()." -> "parProductR", + "cats/FlatMap#forEffectEval()." -> "productLEval", + "cats/FlatMap#followedByEval()." -> "productREval" ) } @@ -265,7 +265,7 @@ case class RenameCartesian(index: SemanticdbIndex) override def fix(ctx: RuleCtx): Patch = { ctx.replaceSymbols( - "_root_.cats.Cartesian." -> "_root_.cats.Semigroupal." + "cats/Cartesian." -> "cats/Semigroupal." )+ ctx.tree.collect { case t @ q"import cats.syntax.cartesian._" => ctx.replaceTree(t, "import cats.syntax.semigroupal._")