diff --git a/scalafix/README.md b/scalafix/README.md index 53d488ba44..88fdb66ca5 100644 --- a/scalafix/README.md +++ b/scalafix/README.md @@ -5,7 +5,7 @@ Install the scalafix sbt plugin (globally or in a specific project): ```scala -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.0-M2") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.0-M3") ``` run @@ -26,12 +26,12 @@ sbt scalafix github:typelevel/cats/v1.0.0 - [x] traverse1_, intercalate1 and sequence1_ in Reducible were renamed to nonEmptyTraverse_, nonEmptyIntercalate and nonEmptySequence_ respectively. +- [x] cats.free.Inject is moved from cats-free to cats-core and renamed to cats.InjectK; cats.data.Prod is renamed to cats.data.Tuple2K; cats.data.Coproduct is renamed to cats.data.EitherK + # WIP - [ ] cats no longer publishes the all-inclusive bundle package "org.typelevel" % "cats", use cats-core, cats-free, or cats-law accordingly instead. If you need cats.free, use "org.typelevel" % "cats-free", if you need cats-laws use "org.typelevel" % "cats-laws", if neither, use "org.typelevel" % "cats-core". -- [ ] cats.free.Inject is moved from cats-free to cats-core and renamed to cats.InjectK; cats.data.Prod is renamed to cats.data.Tuple2K; cats.data.Coproduct is renamed to cats.data.EitherK - - [ ] FunctorFilter, MonadCombine, MonadFilter, MonadReader, MonadState, MonadTrans, MonadWriter and TraverseFilter are no longer in cats, the functionalities they provided are inhereted by the new cats-mtl project. Please check here for migration guide. - [ ] Apply syntax on tuple (e.g. (x, y, z).map3(...)) was moved from cats.syntax.tuple._ to cats.syntax.apply._ and renamed to mapN, contramapN and imapN respectively. diff --git a/scalafix/build.sbt b/scalafix/build.sbt index 2c86feb345..96740db285 100644 --- a/scalafix/build.sbt +++ b/scalafix/build.sbt @@ -10,14 +10,16 @@ lazy val input = project.settings( scalafixSourceroot := sourceDirectory.in(Compile).value, libraryDependencies ++= Seq( "org.typelevel" %% "cats" % "0.9.0" - ) + ), + scalacOptions += "-language:higherKinds" ) lazy val output = project.settings( libraryDependencies ++= Seq( "org.typelevel" %% "cats-core" % "1.0.0-MF", "org.typelevel" %% "cats-free" % "1.0.0-MF" - ) + ), + scalacOptions += "-language:higherKinds" ) lazy val tests = project diff --git a/scalafix/input/src/main/scala/fix/v1_0_0/RenameInjectProdAndCoproduct.scala b/scalafix/input/src/main/scala/fix/v1_0_0/RenameInjectProdAndCoproduct.scala new file mode 100644 index 0000000000..08599b5fbf --- /dev/null +++ b/scalafix/input/src/main/scala/fix/v1_0_0/RenameInjectProdAndCoproduct.scala @@ -0,0 +1,14 @@ +/* +rewrite = "scala:fix.v1_0_0.RenameInjectProdAndCoproduct" + */ +package fix +package to1_0_0 + +import cats.free.Inject +import cats.data.{ Coproduct, Prod } + +object RenameInjectProdAndCoproductTests { + def inject[F[_], G[_]](implicit inj: Inject[F, G]) = ??? + def prod[F[_], G[_], A](implicit prod: Prod[F, G, A]) = ??? + def coprod[F[_], G[_], A](implicit coprod: Coproduct[F, G, A]) = ??? +} diff --git a/scalafix/output/src/main/scala/fix/v1_0_0/RenameInjectProdAndCoproduct.scala b/scalafix/output/src/main/scala/fix/v1_0_0/RenameInjectProdAndCoproduct.scala new file mode 100644 index 0000000000..af8a343a3b --- /dev/null +++ b/scalafix/output/src/main/scala/fix/v1_0_0/RenameInjectProdAndCoproduct.scala @@ -0,0 +1,11 @@ +package fix +package to1_0_0 + +import cats.InjectK +import cats.data.{ EitherK, Tuple2K } + +object RenameInjectProdAndCoproductTests { + def inject[F[_], G[_]](implicit inj: InjectK[F, G]) = ??? + def prod[F[_], G[_], A](implicit prod: Tuple2K[F, G, A]) = ??? + def coprod[F[_], G[_], A](implicit coprod: EitherK[F, G, A]) = ??? +} diff --git a/scalafix/rewrites/src/main/scala/fix/Cats_v1_0_0.scala b/scalafix/rewrites/src/main/scala/fix/Cats_v1_0_0.scala index 3d916eea15..0d34724f76 100644 --- a/scalafix/rewrites/src/main/scala/fix/Cats_v1_0_0.scala +++ b/scalafix/rewrites/src/main/scala/fix/Cats_v1_0_0.scala @@ -86,7 +86,8 @@ case class RemoveCartesianBuilder(semanticCtx: SemanticCtx) } private[this] def wrapInParensIfNeeded(ctx: RewriteCtx, t: Term): Patch = { - if (t.tokens.head.is[Token.LeftParen] && t.tokens.last.is[Token.RightParen]) { + if (t.tokens.head.is[Token.LeftParen] && t.tokens.last + .is[Token.RightParen]) { Patch.empty } else { ctx.addLeft(t.tokens.head, "(") + ctx.addRight(t.tokens.last, ")") @@ -102,7 +103,7 @@ case class RemoveCartesianBuilder(semanticCtx: SemanticCtx) case t: Term.Name => rename(ctx, t, renames) case t @ q"import cats.syntax.cartesian._" => val usesPartialApplies = ctx.tree.collect { - case t: Term.Name if t.isOneOfSymbols(partialApplies) => () + case t: Term.Name if t.isOneOfSymbols(partialApplies) => () }.length > 0 if (usesPartialApplies) { ctx.addRight(t.tokens.last, "\n import cats.syntax.apply._") @@ -216,3 +217,17 @@ case class SimplifyEitherTLift(semanticCtx: SemanticCtx) extends SemanticRewrite } } + +// ref: https://github.com/typelevel/cats/pull/1589 +// https://github.com/typelevel/cats/pull/1596 +case class RenameInjectProdAndCoproduct(semanticCtx: SemanticCtx) extends SemanticRewrite(semanticCtx) { + + def rewrite(ctx: RewriteCtx): 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." + ) + } + +}