Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: check if "NL" for ( is actually not NL #4359

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -9662,3 +9662,17 @@ object a {
}
}
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) =>
(count, id)
})
<<< #4133 partial function within apply, long
maxColumn = 80
===
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) => (count, id) })
14 changes: 14 additions & 0 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9062,3 +9062,17 @@ object a {
}
}
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) =>
(count, id)
})
<<< #4133 partial function within apply, long
maxColumn = 80
===
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) => (count, id) })
14 changes: 14 additions & 0 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9459,3 +9459,17 @@ object a {
}
}
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) =>
(count, id)
})
<<< #4133 partial function within apply, long
maxColumn = 80
===
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) => (count, id) })
Original file line number Diff line number Diff line change
Expand Up @@ -9739,3 +9739,19 @@ object a {
}
}
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) =>
(count, id)
})
<<< #4133 partial function within apply, long
maxColumn = 80
===
rdd.map(
{case (id, count) => (count, id)})
>>>
rdd.map({ case (id, count) =>
(count, id)
})
Loading