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: break on (lambda to keep trailing comma #3855

Merged
merged 1 commit into from
Mar 27, 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 @@ -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
Original file line number Diff line number Diff line change
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(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi: this part will be fixed in a subsequent change

- 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading