Skip to content

Commit

Permalink
Router: break on (lambda to keep trailing comma
Browse files Browse the repository at this point in the history
Other cases already implement this.
  • Loading branch information
kitbellew committed Mar 27, 2024
1 parent c5400b6 commit a9fcf71
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 62 deletions.
Expand Up @@ -865,7 +865,10 @@ class Router(formatOps: FormatOps) {
if (!style.danglingParentheses.callSite) None
else Some(decideNewlinesOnlyBeforeClose(close))
val noSplitMod =
if (style.newlines.alwaysBeforeCurlyLambdaParams) null
if (
style.newlines.alwaysBeforeCurlyLambdaParams ||
getMustDangleForTrailingCommas(tokens.justBefore(close))
) null
else getNoSplit(formatToken, true)

def multilineSpaceSplit(implicit fileLine: FileLine): Split = {
Expand Down
13 changes: 6 additions & 7 deletions scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat
Expand Up @@ -1505,13 +1505,12 @@ object a {
>>>
Idempotency violated
=> Diff (- obtained, + expected)
object a {
- mtd1(x => x + 1) + mtd2(x => x + 1 x +2)
+ mtd1(x => x + 1) + mtd2(x =>
+ x + 1
+ x + 2,
+ )
}
) + mtd2(
- x => x + 1 x +2,
+ x =>
+ x + 1
+ x + 2,
)
<<< rewrite with trailing commas: func in parens and braces, allowFolding
rewrite.rules = [RedundantBraces, RedundantParens]
rewrite.trailingCommas.style = keep
Expand Down
24 changes: 14 additions & 10 deletions scalafmt-tests/src/test/resources/scala3/FewerBraces.stat
Expand Up @@ -1975,17 +1975,21 @@ foo
)
>>>
foo
.mtd1(x => x + 1)
.mtd2(x =>
x + 1
x + 2
,
.mtd1(
x => x + 1,
)
.mtd3(x =>
x + 1
x + 2
x + 3
,
.mtd2(
x =>
x + 1
x + 2
,
)
.mtd3(
x =>
x + 1
x + 2
x + 3
,
)
<<< rewrite to fewer braces: func in parens, infix after
rewrite.rules = [RedundantBraces]
Expand Down
18 changes: 11 additions & 7 deletions scalafmt-tests/src/test/resources/scala3/FewerBraces_fold.stat
Expand Up @@ -1729,13 +1729,17 @@ foo
},
)
>>>
foo.mtd1(x => x + 1).mtd2(x =>
x + 1
x + 2,
).mtd3(x =>
x + 1
x + 2
x + 3,
foo.mtd1(
x => x + 1,
).mtd2(
x =>
x + 1
x + 2,
).mtd3(
x =>
x + 1
x + 2
x + 3,
)
<<< rewrite to fewer braces: func in parens, infix after
rewrite.rules = [RedundantBraces]
Expand Down
25 changes: 14 additions & 11 deletions scalafmt-tests/src/test/resources/scala3/FewerBraces_keep.stat
Expand Up @@ -1948,19 +1948,22 @@ foo
)
>>>
foo
.mtd1(x =>
x + 1,
.mtd1(
x =>
x + 1,
)
.mtd2(x =>
x + 1
x + 2
,
.mtd2(
x =>
x + 1
x + 2
,
)
.mtd3(x =>
x + 1
x + 2
x + 3
,
.mtd3(
x =>
x + 1
x + 2
x + 3
,
)
<<< rewrite to fewer braces: func in parens, infix after
rewrite.rules = [RedundantBraces]
Expand Down
20 changes: 12 additions & 8 deletions scalafmt-tests/src/test/resources/scala3/FewerBraces_unfold.stat
Expand Up @@ -1964,15 +1964,19 @@ foo
)
>>>
foo
.mtd1(x => x + 1)
.mtd2(x =>
x + 1
x + 2,
.mtd1(
x => x + 1,
)
.mtd3(x =>
x + 1
x + 2
x + 3,
.mtd2(
x =>
x + 1
x + 2,
)
.mtd3(
x =>
x + 1
x + 2
x + 3,
)
<<< rewrite to fewer braces: func in parens, infix after
rewrite.rules = [RedundantBraces]
Expand Down
Expand Up @@ -397,9 +397,11 @@ foo.mtd(
},
)
>>>
foo.mtd(x => {
x + 1
})
foo.mtd(
x => {
x + 1
},
)
<<< partial func in parens, !allowFolding
rewrite.trailingCommas.allowFolding = false
===
Expand Down Expand Up @@ -430,9 +432,11 @@ object a {
}
>>>
object a {
foo.mtd(bar(x => {
x + 1
}))
foo.mtd(bar(
x => {
x + 1
},
))
foo.mtd(
bar(x => {
x + 1
Expand All @@ -445,21 +449,24 @@ binPack.indentCallSiteOnce = true
rewrite.trailingCommas.allowFolding = false
===
object a {
foo.mtd(bar(x => {
x + 1
},
))
foo.mtd(bar(x => {
x + 1
}
),
)
foo.mtd(bar(
x => {
x + 1
},
))
foo.mtd(
bar(x => {
x + 1
}),
)
}
>>>
object a {
foo.mtd(bar(x => {
x + 1
}))
foo.mtd(bar(
x => {
x + 1
},
))
foo.mtd(
bar(x => {
x + 1
Expand Down

0 comments on commit a9fcf71

Please sign in to comment.