From febc3b687183997570ba410a6881956e906a01b4 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sun, 24 Dec 2023 15:07:50 +0900 Subject: [PATCH] EtaExpansionRewrite --- .../src/main/scala/fix/EtaExpansionRewrite.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 rules/src/main/scala/fix/EtaExpansionRewrite.scala diff --git a/rules/src/main/scala/fix/EtaExpansionRewrite.scala b/rules/src/main/scala/fix/EtaExpansionRewrite.scala new file mode 100644 index 0000000..9112797 --- /dev/null +++ b/rules/src/main/scala/fix/EtaExpansionRewrite.scala @@ -0,0 +1,15 @@ +package fix + +import scala.meta.Term +import scalafix.Patch +import scalafix.v1.SyntacticDocument +import scalafix.v1.SyntacticRule +import scala.meta.tokens.Token + +class EtaExpansionRewrite extends SyntacticRule("EtaExpansionRewrite") { + override def fix(implicit doc: SyntacticDocument): Patch = { + doc.tree.collect { case t @ Term.Eta(x) => + t.tokens.reverseIterator.find(_.is[Token.Underscore]).filter(_.start > x.pos.end).map(Patch.removeToken).asPatch + }.asPatch + } +}