From 932540d6d43628d6857d01b13a525f8c00062ac4 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sat, 30 Mar 2024 19:26:03 +0900 Subject: [PATCH] skip scalameta bug 2921 convert if new version --- .../scalameta_ast/ScalametaBug2921.scala | 7 +++++++ .../scalameta_ast/ScalametaBug2921.scala | 17 +++++++++++++++++ .../main/scala/scalameta_ast/ScalametaAST.scala | 11 +---------- .../scalameta_ast/ScalametaBug2921.scala | 7 +++++++ 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 core/src/main/scala-latest-js/scalameta_ast/ScalametaBug2921.scala create mode 100644 core/src/main/scala-scalafix_compat-js/scalameta_ast/ScalametaBug2921.scala create mode 100644 core/src/main/scalajvm/scalameta_ast/ScalametaBug2921.scala diff --git a/core/src/main/scala-latest-js/scalameta_ast/ScalametaBug2921.scala b/core/src/main/scala-latest-js/scalameta_ast/ScalametaBug2921.scala new file mode 100644 index 0000000..777d940 --- /dev/null +++ b/core/src/main/scala-latest-js/scalameta_ast/ScalametaBug2921.scala @@ -0,0 +1,7 @@ +package scalameta_ast + +import scala.meta.Tree + +object ScalametaBug2921 { + def convert(t: Tree): String = t.structure +} diff --git a/core/src/main/scala-scalafix_compat-js/scalameta_ast/ScalametaBug2921.scala b/core/src/main/scala-scalafix_compat-js/scalameta_ast/ScalametaBug2921.scala new file mode 100644 index 0000000..ae16ec9 --- /dev/null +++ b/core/src/main/scala-scalafix_compat-js/scalameta_ast/ScalametaBug2921.scala @@ -0,0 +1,17 @@ +package scalameta_ast + +import scala.meta.Tree + +object ScalametaBug2921 { + // https://github.com/scalameta/scalameta/pull/2921 + private[this] val scalametaBugWorkaround: Seq[(String, String)] = Seq( + "Lit.Unit(())" -> "Lit.Unit()", + "Lit.Null(null)" -> "Lit.Null()" + ) + + def convert(t: Tree): String = { + scalametaBugWorkaround.foldLeft(t.structure) { case (s, (x1, x2)) => + s.replace(x1, x2) + } + } +} diff --git a/core/src/main/scala/scalameta_ast/ScalametaAST.scala b/core/src/main/scala/scalameta_ast/ScalametaAST.scala index b7a60be..c44762c 100644 --- a/core/src/main/scala/scalameta_ast/ScalametaAST.scala +++ b/core/src/main/scala/scalameta_ast/ScalametaAST.scala @@ -91,13 +91,6 @@ class ScalametaAST { private val convert = implicitly[Convert[String, Input]] - // TODO remove when scalafix depends on new scalameta version - // https://github.com/scalameta/scalameta/pull/2921 - private[this] val scalametaBugWorkaround: Seq[(String, String)] = Seq( - "Lit.Unit(())" -> "Lit.Unit()", - "Lit.Null(null)" -> "Lit.Null()" - ) - private def isValidTermName(str: String): Boolean = { implicitly[Parse[Term]].apply(Input.String(str), dialects.Scala3).toOption.exists(_.is[Term.Name]) } @@ -310,9 +303,7 @@ class ScalametaAST { x2 <- dialects } yield (x1, x2) ) - val str = scalametaBugWorkaround.foldLeft(tree.structure) { case (s, (x1, x2)) => - s.replace(x1, x2) - } + val str = ScalametaBug2921.convert(tree) lazy val parsed = implicitly[Parse[Term]].apply(Input.String(str), scala.meta.dialects.Scala3).get val parsedOpt = PartialFunction.condOpt(args) { case x: ScalafixRule => ParsedValue(() => parsed, x) diff --git a/core/src/main/scalajvm/scalameta_ast/ScalametaBug2921.scala b/core/src/main/scalajvm/scalameta_ast/ScalametaBug2921.scala new file mode 100644 index 0000000..777d940 --- /dev/null +++ b/core/src/main/scalajvm/scalameta_ast/ScalametaBug2921.scala @@ -0,0 +1,7 @@ +package scalameta_ast + +import scala.meta.Tree + +object ScalametaBug2921 { + def convert(t: Tree): String = t.structure +}