From 4de56122ddb5636510fd3c3b9393900fde331b70 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sun, 8 Oct 2023 09:39:21 +0900 Subject: [PATCH] fix StringFormatToInterpolation --- .../src/main/scala/fix/StringFormatToInterpolationTest.scala | 4 ++++ .../src/main/scala/fix/StringFormatToInterpolationTest.scala | 4 ++++ rules/src/main/scala/fix/StringFormatToInterpolation.scala | 1 + 3 files changed, 9 insertions(+) diff --git a/input/src/main/scala/fix/StringFormatToInterpolationTest.scala b/input/src/main/scala/fix/StringFormatToInterpolationTest.scala index 51c3f61..31294c7 100644 --- a/input/src/main/scala/fix/StringFormatToInterpolationTest.scala +++ b/input/src/main/scala/fix/StringFormatToInterpolationTest.scala @@ -27,4 +27,8 @@ class StringFormatToInterpolationTest { "%s b".format(Some(4)) "%s %s %s".format(1, None) + + """%s \ """.format("x") + + "%s \\ ".format("x") } diff --git a/output/src/main/scala/fix/StringFormatToInterpolationTest.scala b/output/src/main/scala/fix/StringFormatToInterpolationTest.scala index b557306..bea39e1 100644 --- a/output/src/main/scala/fix/StringFormatToInterpolationTest.scala +++ b/output/src/main/scala/fix/StringFormatToInterpolationTest.scala @@ -24,4 +24,8 @@ class StringFormatToInterpolationTest { s"${Some(4)} b" "%s %s %s".format(1, None) + + """%s \ """.format("x") + + "%s \\ ".format("x") } diff --git a/rules/src/main/scala/fix/StringFormatToInterpolation.scala b/rules/src/main/scala/fix/StringFormatToInterpolation.scala index afde9b3..261f98c 100644 --- a/rules/src/main/scala/fix/StringFormatToInterpolation.scala +++ b/rules/src/main/scala/fix/StringFormatToInterpolation.scala @@ -30,6 +30,7 @@ private object StringFormatToInterpolation { case (s, args) if args.nonEmpty && args.lengthCompare(s.value.sliding(2).count(_ == "%s")) == 0 && + s.value.forall(_ != '\\') && // TODO support backslash !args.exists(_.is[Term.Placeholder]) => (s.syntax.startsWith("\"\"\""), s.value, args) }