Skip to content

Commit

Permalink
added scalafix to rename Cartesian to Semigroupal
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang committed Oct 10, 2017
1 parent de6345e commit f42419b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package object syntax {
object bifunctor extends BifunctorSyntax
object bifoldable extends BifoldableSyntax
object bitraverse extends BitraverseSyntax
object semigroupal extends SemigroupalSyntax
object coflatMap extends CoflatMapSyntax
object eitherK extends EitherKSyntax
object comonad extends ComonadSyntax
Expand All @@ -34,6 +33,7 @@ package object syntax {
object profunctor extends ProfunctorSyntax
object reducible extends ReducibleSyntax
object semigroup extends SemigroupSyntax
object semigroupal extends SemigroupalSyntax
object semigroupk extends SemigroupKSyntax
object show extends ShowSyntax
object strong extends StrongSyntax
Expand Down
10 changes: 10 additions & 0 deletions scalafix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ sbt scalafix github:typelevel/cats/v1.0.0
- [ ] foldLeftM is removed from Free, use foldM on Foldable instead, see #1117 for detail.

- [ ] iteratorFoldM was removed from Foldable due to #1716


## To test scala fix

```bash
sbt ;coreJVM/publishLocal;coreFree/publishLocal
cd scalafix
sbt test

```
13 changes: 13 additions & 0 deletions scalafix/input/src/main/scala/fix/v1_0_0/RenameCartesian.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
rule = "scala:fix.v1_0_0.RenameCartesian"
*/
package fix
package to1_0_0

import cats.Cartesian

object RenameCartesianTests {
import cats.syntax.cartesian._

def prod[F[_]: Cartesian, A, B](fa: F[A], fb: F[B]): F[(A, B)] = Cartesian[F].product(fa, fb)
}
10 changes: 10 additions & 0 deletions scalafix/output/src/main/scala/fix/v1_0_0/RenameCartesian.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fix
package to1_0_0

import cats.Semigroupal

object RenameCartesianTests {
import cats.syntax.semigroupal._

def prod[F[_]: Semigroupal, A, B](fa: F[A], fb: F[B]): F[(A, B)] = Semigroupal[F].product(fa, fb)
}
17 changes: 16 additions & 1 deletion scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,19 @@ case class RenameEitherTLiftT(index: SemanticdbIndex)
"_root_.cats.data.EitherTFunctions.liftT." -> "liftF"
)

}
}

// ref: https://github.com/typelevel/cats/pull/1960
case class RenameCartesian(index: SemanticdbIndex)
extends SemanticRule(index, "RenameCartesian") {

override def fix(ctx: RuleCtx): Patch = {
ctx.replaceSymbols(
"_root_.cats.Cartesian." -> "_root_.cats.Semigroupal."
)+ ctx.tree.collect {
case t @ q"import cats.syntax.cartesian._" =>
ctx.replaceTree(t, "import cats.syntax.semigroupal._")
}.asPatch
}

}

0 comments on commit f42419b

Please sign in to comment.