From d4eee69c1bf64ba1cb68f3db894b28eaaae430a9 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Thu, 28 Dec 2023 17:42:33 +0900 Subject: [PATCH] WildcardTypeRewrite --- .../src/main/scala/fix/WildcardTypeRewrite.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 rules/src/main/scala/fix/WildcardTypeRewrite.scala diff --git a/rules/src/main/scala/fix/WildcardTypeRewrite.scala b/rules/src/main/scala/fix/WildcardTypeRewrite.scala new file mode 100644 index 0000000..2cf5762 --- /dev/null +++ b/rules/src/main/scala/fix/WildcardTypeRewrite.scala @@ -0,0 +1,15 @@ +package fix + +import scala.meta.Type +import scalafix.Patch +import scalafix.v1.SyntacticDocument +import scalafix.v1.SyntacticRule +import scala.meta.tokens.Token + +class WildcardTypeRewrite extends SyntacticRule("WildcardTypeRewrite") { + override def fix(implicit doc: SyntacticDocument): Patch = { + doc.tree.collect { case t: Type.Wildcard => + t.tokens.find(_.is[Token.Underscore]).map(x => Patch.replaceToken(x, "?")).asPatch + }.asPatch + } +}