Created
April 24, 2026 04:13
-
-
Save xuwei-k/5f7578e3eda59b009bea6cd696a0b099 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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