Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created February 19, 2022 06:39
Show Gist options
  • Save xuwei-k/96726bd86e70d599c3a6b0666f6bbb3d to your computer and use it in GitHub Desktop.
Save xuwei-k/96726bd86e70d599c3a6b0666f6bbb3d to your computer and use it in GitHub Desktop.
package fix
import scalafix.Patch
import scalafix.v1.SyntacticDocument
import scalafix.v1.SyntacticRule
import scala.meta.Term
import scala.meta.Type
class MockitoPureEff extends SyntacticRule("MockitoPureEff") {
override def fix(implicit doc: SyntacticDocument): Patch = {
doc.tree.collect {
case Term.Apply(
Term.Select(
Term.Apply(
Term.Name("when"),
List(
Term.Apply(
Term.ApplyType(
Term.Select(
_,
_
),
List(
Type.Name(tpe)
)
),
_
)
)
),
Term.Name("thenReturn")
),
List(
ret @ Term.Select(
_,
Term.Name("pureEff")
)
)
) =>
Patch.addRight(ret, s"[${tpe}]")
}.asPatch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment