From cfb23d4673b65208d64025fb8b733733970e7966 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Mon, 22 May 2023 10:07:12 -0700 Subject: [PATCH] RedundantBraces: don't remove parens in Init args --- .../src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala | 3 ++- .../src/test/resources/rewrite/RedundantBraces.stat | 4 +--- 2 files changed, 3 insertions(+), 4 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 e426c33f76..959c32870c 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 @@ -114,7 +114,8 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule { // single-arg apply of a partial function // a({ case b => c; d }) change to a { case b => c; d } def lpPartialFunction = rtOwner match { - case ta @ Term.ArgClause(arg :: Nil, _) => + case ta @ Term.ArgClause(arg :: Nil, _) + if !ta.parent.exists(_.is[Init]) => getOpeningParen(ta).map { lp => val ko = lp.ne(rt) || getBlockNestedPartialFunction(arg).isEmpty if (ko) null else removeToken diff --git a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat index fe69a2c724..ef43893387 100644 --- a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat +++ b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat @@ -1389,6 +1389,4 @@ object A: <<< #3540 object Bar extends Foo[(Int, String)]({ case (i, s) => () }) >>> -test does not parse -object Bar extends Foo[(Int, String)] { case (i, s) => () } - ^ +object Bar extends Foo[(Int, String)]({ case (i, s) => () })