From 54a6df577610600aa2ec838bf7d9632f863cb672 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 2 Apr 2024 06:43:58 -0700 Subject: [PATCH 1/2] Add test showing non-redundant-braces in xml --- .../resources/rewrite/RedundantBracesStrInterpolation.stat | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat b/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat index 3462df9308..eb0975612d 100644 --- a/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat +++ b/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat @@ -100,3 +100,9 @@ object Test { object Test { s"${foo}_${bar}" } +<<< #3891 braces within xml + +>>> +org.scalafmt.util.FormatException: org.scalafmt.Error$PreciseIncomplete: ...: error: Unable to format file due to bug in scalafmt + + ^ From 2a09edf4699ac5aa4cd93f1cd30826c4dcd77bd4 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 2 Apr 2024 06:50:06 -0700 Subject: [PATCH 2/2] RedundantBraces: ignore block under Term.Xml --- .../src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala | 1 + .../resources/rewrite/RedundantBracesStrInterpolation.stat | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala index 4c1e4fca16..a336ee9574 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala @@ -244,6 +244,7 @@ class RedundantBraces(implicit val ftoks: FormatTokens) case Some(f: Term.FunctionTerm) if okToReplaceFunctionInSingleArgApply(f) => removeToken case Some(_: Term.Interpolate) => handleInterpolation + case Some(_: Term.Xml) => null case _ => if (processBlock(t)) removeToken else null } case _: Term.Interpolate => handleInterpolation diff --git a/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat b/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat index eb0975612d..e500e857bf 100644 --- a/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat +++ b/scalafmt-tests/src/test/resources/rewrite/RedundantBracesStrInterpolation.stat @@ -103,6 +103,4 @@ object Test { <<< #3891 braces within xml >>> -org.scalafmt.util.FormatException: org.scalafmt.Error$PreciseIncomplete: ...: error: Unable to format file due to bug in scalafmt - - ^ +