diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 789fef9b93..7066451681 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -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 = { diff --git a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat index 2f07fe3004..1f181c001e 100644 --- a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat +++ b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces.stat @@ -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 diff --git a/scalafmt-tests/src/test/resources/scala3/FewerBraces.stat b/scalafmt-tests/src/test/resources/scala3/FewerBraces.stat index dbeb6b004d..83ad131015 100644 --- a/scalafmt-tests/src/test/resources/scala3/FewerBraces.stat +++ b/scalafmt-tests/src/test/resources/scala3/FewerBraces.stat @@ -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] diff --git a/scalafmt-tests/src/test/resources/scala3/FewerBraces_fold.stat b/scalafmt-tests/src/test/resources/scala3/FewerBraces_fold.stat index edb4bf4bbe..6fd7ecf593 100644 --- a/scalafmt-tests/src/test/resources/scala3/FewerBraces_fold.stat +++ b/scalafmt-tests/src/test/resources/scala3/FewerBraces_fold.stat @@ -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] diff --git a/scalafmt-tests/src/test/resources/scala3/FewerBraces_keep.stat b/scalafmt-tests/src/test/resources/scala3/FewerBraces_keep.stat index f139c86826..a80b517e08 100644 --- a/scalafmt-tests/src/test/resources/scala3/FewerBraces_keep.stat +++ b/scalafmt-tests/src/test/resources/scala3/FewerBraces_keep.stat @@ -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] diff --git a/scalafmt-tests/src/test/resources/scala3/FewerBraces_unfold.stat b/scalafmt-tests/src/test/resources/scala3/FewerBraces_unfold.stat index 5e6ebee255..ec5c88fa69 100644 --- a/scalafmt-tests/src/test/resources/scala3/FewerBraces_unfold.stat +++ b/scalafmt-tests/src/test/resources/scala3/FewerBraces_unfold.stat @@ -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] diff --git a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat index 918e8fb193..7da796ed1f 100644 --- a/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat +++ b/scalafmt-tests/src/test/resources/trailing-commas/trailingCommasPreserve.stat @@ -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 === @@ -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 @@ -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