Skip to content

Commit

Permalink
Router: fold closing paren if no NL after opening
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 7, 2024
1 parent 3c4286c commit c96ac7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -936,9 +936,15 @@ class Router(formatOps: FormatOps) {
).left

val spacePolicy = SingleLineBlock(lambdaToken) ==> {
Policy ? lambdaIsABlock || delayedBreakPolicy(
Policy.End == lambdaLeft.getOrElse(close),
)(newlinePolicy)
def before = Policy.End < close ==> Policy.on(close, "NODANGLE") {
case Decision(FormatToken(bc, `close`, _), _) =>
val isSpace = bc.is[T.Comment] || style.spaces.inParentheses
Seq(Split(Space(isSpace), 0))
}
Policy ? lambdaIsABlock ||
Policy.RelayOnSplit.by(Policy.End == lambdaLeft.getOrElse(close))(
(s, _) => s.isNL,
)(before)(newlinePolicy)
}
Split(noSplitMod, 0, policy = spacePolicy)
.withOptimalToken(lambdaToken, killOnFail = true)
Expand Down
24 changes: 8 additions & 16 deletions scalafmt-tests/shared/src/test/resources/rewrite/AvoidInfix.stat
Original file line number Diff line number Diff line change
Expand Up @@ -744,29 +744,21 @@ newlines.avoidForSimpleOverflow = all
===
def templates = symbols filter (x => x.isClass || x.isTrait || x == AnyRefClass/* which is now a type alias */) toSet
>>>
Idempotency violated
=> Diff (- obtained, + expected)
-def templates = symbols.filter(x => x.isClass || x.isTrait || x == AnyRefClass /* which is now a type alias */
-) toSet
+def templates = symbols
+ .filter(x =>
+ x.isClass || x.isTrait || x == AnyRefClass /* which is now a type alias */
+ ) toSet
def templates = symbols
.filter(x =>
x.isClass || x.isTrait || x == AnyRefClass /* which is now a type alias */
) toSet
<<< #4133 select, apply with comment before closing paren, and postfix
maxColumn = 78
newlines.source = fold
newlines.avoidForSimpleOverflow = all
===
def templates = symbols.filter (x => x.isClass || x.isTrait || x == AnyRefClass/* which is now a type alias */) toSet
>>>
Idempotency violated
=> Diff (- obtained, + expected)
-def templates = symbols.filter(x => x.isClass || x.isTrait || x == AnyRefClass /* which is now a type alias */
-) toSet
+def templates = symbols
+ .filter(x =>
+ x.isClass || x.isTrait || x == AnyRefClass /* which is now a type alias */
+ ) toSet
def templates = symbols
.filter(x =>
x.isClass || x.isTrait || x == AnyRefClass /* which is now a type alias */
) toSet
<<< #4133 select, apply with comment before closing paren, and select
maxColumn = 78
newlines.source = fold
Expand Down

0 comments on commit c96ac7e

Please sign in to comment.