From c4b84e9d63212075127ca34e9d7d450c3d016bc4 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 28 Sep 2024 09:00:14 -0700 Subject: [PATCH] Router: check if "NL" for `(` is actually not NL That will require that the regular no-NL split is produced, as well. --- .../scala/org/scalafmt/internal/Router.scala | 18 +++++++++--------- .../test/resources/newlines/source_keep.stat | 17 ++++------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 06763c9536..ba973954a5 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -923,13 +923,14 @@ class Router(formatOps: FormatOps) { (if (onlyConfigStyle) opensConfigStyleImplicitParamList(ft) else hasImplicitParamList(rightOwner)) + val noSplitForNL = !onlyConfigStyle && right.is[T.LeftBrace] + val skipNoSplit = !noSplitForNL && + (style.newlines.keepBreak(newlines) || { + if (!handleImplicit) onlyConfigStyle + else style.newlines.forceBeforeImplicitParamListModifier + }) val noSplitMod = - if ( - style.newlines.keepBreak(newlines) || { - if (!handleImplicit) onlyConfigStyle - else style.newlines.forceBeforeImplicitParamListModifier - } - ) null + if (skipNoSplit) null else getNoSplitAfterOpening(ft, commentNL = null, spaceOk = !isBracket) val rightIsComment = right.is[T.Comment] @@ -1086,10 +1087,9 @@ class Router(formatOps: FormatOps) { if (multipleArgs) Split(Newline, cost, policy = oneArgOneLine) .withIndent(extraOneArgPerLineIndent) else { - val noSplit = !onlyConfigStyle && right.is[T.LeftBrace] - val noConfigStyle = noSplit || newlinePolicy.isEmpty || + val noConfigStyle = noSplitForNL || newlinePolicy.isEmpty || !configStyleFlag - Split(NoSplit.orNL(noSplit), cost, policy = newlinePolicy) + Split(NoSplit.orNL(noSplitForNL), cost, policy = newlinePolicy) .andPolicy(Policy ? noConfigStyle && singleLine(4)).andPolicy( Policy ? singleArgument && asInfixApp(args.head) .map(InfixSplits(_, ft).nlPolicy), diff --git a/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat b/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat index f849f2c014..eaabfbff81 100644 --- a/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat @@ -9463,22 +9463,13 @@ object a { rdd.map( {case (id, count) => (count, id)}) >>> -Idempotency violated -=> Diff (- obtained, + expected) - rdd.map({ case (id, count) => -- (count, id) --}) -+ (count, id) -+ } -+) +rdd.map({ case (id, count) => + (count, id) +}) <<< #4133 partial function within apply, long maxColumn = 80 === rdd.map( {case (id, count) => (count, id)}) >>> -Idempotency violated -=> Diff (- obtained, + expected) --rdd.map({ case (id, count) => (count, id) }) -+rdd.map({ case (id, count) => (count, id) } -+) +rdd.map({ case (id, count) => (count, id) })