Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created April 24, 2026 04:13
Show Gist options
  • Select an option

  • Save xuwei-k/5f7578e3eda59b009bea6cd696a0b099 to your computer and use it in GitHub Desktop.

Select an option

Save xuwei-k/5f7578e3eda59b009bea6cd696a0b099 to your computer and use it in GitHub Desktop.
package fix
import fix.PlayJsonReadsWrites.ImplicitValOrGiven
import scala.meta._
import scalafix.v1._
object PlayJsonReadsWrites {
private object ImplicitValOrGiven {
def unapply(t: Tree): Option[Type] = PartialFunction.condOpt(t) {
case g: Defn.GivenAlias => g.decltpe
case v @ Defn.Val(
_,
Pat.Var(_: Term.Name) :: Nil,
Some(
tpe
),
_
) if v.mods.exists(_.is[Mod.Implicit]) => tpe
}
}
}
class PlayJsonReadsWrites extends SyntacticRule("PlayJsonReadsWrites") {
override def fix(implicit doc: SyntacticDocument): Patch = {
doc.tree.collect {
case t: Stat =>
val writes = t.collect{
case ImplicitValOrGiven(
Type.Apply.After_4_6_0(
Type.Name("Writes"),
Type.ArgClause(
List(
tpe
)
)
)
) =>
tpe
}
val reads = t.collect{
case ImplicitValOrGiven(
Type.Apply.After_4_6_0(
Type.Name("Reads"),
Type.ArgClause(
List(
tpe
)
)
)
) =>
tpe
}
writes.filter(w => reads.exists(_.structure == w.structure)).map{
w =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = w.pos
)
)
}.asPatch
}.asPatch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment