Skip to content

Commit

Permalink
Router: check if "NL" for ( is actually not NL
Browse files Browse the repository at this point in the history
That will require that the regular no-NL split is produced, as well.
  • Loading branch information
kitbellew committed Sep 28, 2024
1 parent 26f1487 commit c4b84e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 4 additions & 13 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -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) })

0 comments on commit c4b84e9

Please sign in to comment.