From b8c334ebb8d5c04096be0c4dc4c6eb5c554c702a Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 31 Aug 2023 09:30:52 -0700 Subject: [PATCH] FormatOps: fewer-braces func not just in apply --- .../main/scala/org/scalafmt/internal/FormatOps.scala | 3 +-- .../src/test/resources/scala3/OptionalBraces.stat | 10 ++++------ .../src/test/resources/scala3/OptionalBraces_fold.stat | 10 ++++------ .../src/test/resources/scala3/OptionalBraces_keep.stat | 5 +++-- .../test/resources/scala3/OptionalBraces_unfold.stat | 10 ++++------ 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 5d053c8e6c..1efbfd471c 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -2130,8 +2130,7 @@ class FormatOps( def owner = t.parent def splits = Some(t.values match { case (tf: Term.FunctionTerm) :: Nil - if !style.newlines.alwaysBeforeCurlyLambdaParams && - t.parent.exists(_.is[Term.Apply]) => + if !style.newlines.alwaysBeforeCurlyLambdaParams => getSplits(ft, t, forceNL = false, indentOpt = indent) match { case s +: rs if !s.isNL => funcSplit(tf)(s.fileLine) +: rs case ss => ss diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat index b57171acad..8d58c20420 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat @@ -5167,10 +5167,9 @@ object a: List(1, 2, 3) map: x => x + 1 >>> -test does not parse object a: - List(1, 2, 3) map: x => x + 1 - ^ + List(1, 2, 3) map: + x => x + 1 <<< #3623 !beforeCurlyLambdaParams newlines.beforeCurlyLambdaParams = false === @@ -5178,7 +5177,6 @@ object a: List(1, 2, 3) map: x => x + 1 >>> -test does not parse object a: - List(1, 2, 3) map: x => x + 1 - ^ + List(1, 2, 3) map: x => + x + 1 diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat index 7269cb2de1..651e2d3347 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat @@ -4934,10 +4934,9 @@ object a: List(1, 2, 3) map: x => x + 1 >>> -test does not parse object a: - List(1, 2, 3) map: x => x + 1 - ^ + List(1, 2, 3) map: + x => x + 1 <<< #3623 !beforeCurlyLambdaParams newlines.beforeCurlyLambdaParams = false === @@ -4945,7 +4944,6 @@ object a: List(1, 2, 3) map: x => x + 1 >>> -test does not parse object a: - List(1, 2, 3) map: x => x + 1 - ^ + List(1, 2, 3) map: x => + x + 1 diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat index 090e5f0483..d6772e0e81 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat @@ -5202,8 +5202,9 @@ object a: x + 1 >>> object a: - List(1, 2, 3) map: x => - x + 1 + List(1, 2, 3) map: + x => + x + 1 <<< #3623 !beforeCurlyLambdaParams newlines.beforeCurlyLambdaParams = false === diff --git a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat index 973a7b5974..270c1a630c 100644 --- a/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -5333,10 +5333,9 @@ object a: List(1, 2, 3) map: x => x + 1 >>> -test does not parse object a: - List(1, 2, 3) map: x => x + 1 - ^ + List(1, 2, 3) map: + x => x + 1 <<< #3623 !beforeCurlyLambdaParams newlines.beforeCurlyLambdaParams = false === @@ -5344,7 +5343,6 @@ object a: List(1, 2, 3) map: x => x + 1 >>> -test does not parse object a: - List(1, 2, 3) map: x => x + 1 - ^ + List(1, 2, 3) map: x => + x + 1