From 32e43b367eabf8edb051b57966058a93248feb56 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Mon, 8 Jan 2024 14:07:30 +0900 Subject: [PATCH] fix StringFormatToInterpolation --- input/src/main/scala/fix/StringFormatToInterpolationTest.scala | 2 ++ output/src/main/scala/fix/StringFormatToInterpolationTest.scala | 2 ++ rules/src/main/scala/fix/StringFormatToInterpolation.scala | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/input/src/main/scala/fix/StringFormatToInterpolationTest.scala b/input/src/main/scala/fix/StringFormatToInterpolationTest.scala index dc0f257..e575679 100644 --- a/input/src/main/scala/fix/StringFormatToInterpolationTest.scala +++ b/input/src/main/scala/fix/StringFormatToInterpolationTest.scala @@ -33,4 +33,6 @@ class StringFormatToInterpolationTest { "%s \\ ".format("x") " %s \" ".format("x") + + "\n %s aaa \n %s bbb".format(1, 2) } diff --git a/output/src/main/scala/fix/StringFormatToInterpolationTest.scala b/output/src/main/scala/fix/StringFormatToInterpolationTest.scala index f814549..2adb86e 100644 --- a/output/src/main/scala/fix/StringFormatToInterpolationTest.scala +++ b/output/src/main/scala/fix/StringFormatToInterpolationTest.scala @@ -30,4 +30,6 @@ class StringFormatToInterpolationTest { "%s \\ ".format("x") " %s \" ".format("x") + + s"\n ${1} aaa \n ${2} bbb" } diff --git a/rules/src/main/scala/fix/StringFormatToInterpolation.scala b/rules/src/main/scala/fix/StringFormatToInterpolation.scala index 3b47a0b..69e4a5f 100644 --- a/rules/src/main/scala/fix/StringFormatToInterpolation.scala +++ b/rules/src/main/scala/fix/StringFormatToInterpolation.scala @@ -48,7 +48,7 @@ class StringFormatToInterpolation extends SyntacticRule("StringFormatToInterpola new java.lang.StringBuilder("s\"") } str.split("%s", -1).zipWithIndex.foreach { case (s, i) => - buf.append(s) + buf.append(s.replace("\n", "\\n")) if (i < args.length) { buf.append("${") buf.append(args(i))