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 996a2c9 commit dbfd560
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class CommunityScala2Suite(name: String)

class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

override protected def totalStatesVisited: Option[Int] = Some(34661412)
override protected def totalStatesVisited: Option[Int] = Some(34661420)

override protected def builds =
Seq(getBuild("v2.12.20", dialects.Scala212, 1277))
Expand All @@ -18,7 +18,7 @@ class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {

class CommunityScala2_13Suite extends CommunityScala2Suite("scala-2.13") {

override protected def totalStatesVisited: Option[Int] = Some(43185118)
override protected def totalStatesVisited: Option[Int] = Some(43185150)

override protected def builds =
Seq(getBuild("v2.13.14", dialects.Scala213, 1287))
Expand Down
48 changes: 16 additions & 32 deletions scalafmt-tests/shared/src/test/resources/rewrite/AvoidInfix.stat
Original file line number Diff line number Diff line change
Expand Up @@ -754,29 +754,21 @@ newlines.avoidForSimpleOverflow = [slc]
===
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 infix, with comment before closing paren, and postfix; overflow all
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 postfix; overflow punct
maxColumn = 78
newlines.source = fold
Expand All @@ -794,29 +786,21 @@ newlines.avoidForSimpleOverflow = [slc]
===
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; overflow all
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; overflow punct
maxColumn = 78
newlines.source = fold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1500765, "total explored")
assertEquals(explored, 1501221, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down

0 comments on commit dbfd560

Please sign in to comment.