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: binpack defn single-line to avoid overflow #3010

Merged
merged 1 commit into from
Dec 28, 2021
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 @@ -1101,9 +1101,9 @@ class Router(formatOps: FormatOps) {
val mustDangle = onlyConfigStyle ||
style.danglingParentheses.defnSite &&
(style.newlines.sourceIgnored || !style.optIn.configStyleArguments)
val slbOnly = mustDangle || style.newlines.source.eq(Newlines.unfold)
def noSplitPolicy: Policy =
if (mustDangle || style.newlines.source.eq(Newlines.unfold))
slbPolicy
if (slbOnly) slbPolicy
else {
val penalizeOpens = bracketPenalty.fold(Policy.noPolicy) { p =>
Policy.before(close) {
Expand Down Expand Up @@ -1132,11 +1132,11 @@ class Router(formatOps: FormatOps) {
def nlCost = bracketPenalty.getOrElse(1)

Seq(
Split(noSplitModification, 0)
.notIf(mustUseNL)
Split(mustUseNL, 0)(noSplitModification)
.withOptimalToken(close, ignore = !slbOnly, killOnFail = true)
.withPolicy(noSplitPolicy)
.withIndents(noSplitIndents),
Split(nlMod, if (mustUseNL) 0 else nlCost)
Split(nlMod, if (mustUseNL || slbOnly) 0 else nlCost)
.withPolicy(nlDanglePolicy & onelinePolicy & penalizeBrackets)
.withIndent(indent)
)
Expand Down
6 changes: 3 additions & 3 deletions scalafmt-tests/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4382,9 +4382,9 @@ object a {
}
>>>
object a {
def foo(
bb: BB, cc: CC, dd: DD = DDD.ddd
): Bar[Baz] = {
def foo(bb: BB, cc: CC, dd: DD = DDD.ddd): Bar[
Baz
] = {
// c
qux
}
Expand Down
6 changes: 3 additions & 3 deletions scalafmt-tests/src/test/resources/newlines/source_unfold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4807,9 +4807,9 @@ object a {
}
>>>
object a {
def foo(
bb: BB, cc: CC, dd: DD = DDD.ddd
): Bar[Baz] = {
def foo(bb: BB, cc: CC, dd: DD = DDD.ddd): Bar[
Baz
] = {
// c
qux
}
Expand Down