Skip to content

Commit

Permalink
Router: detect rewritten blocks before else
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 22, 2024
1 parent 0186bc9 commit 9372a12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,12 @@ class FormatOps(
.map { ftElsep =>
val beforeElsep = prevNonCommentBefore(ftElsep)
val elsOpt = beforeElsep.left match {
case els: T.KwElse
if initStyle.newlines.alwaysBeforeElseAfterCurlyIf ||
!prev(beforeElsep).left.is[T.RightBrace] => Some(els)
case els: T.KwElse if initStyle.newlines.alwaysBeforeElseAfterCurlyIf || ! {
val rb = prev(beforeElsep).left
rb.is[T.RightBrace] && matchingOpt(rb).exists { lb =>
prev(lb).left.end <= term.thenp.pos.start
}
} => Some(els)
case _ => None
}
(ftElsep, elsOpt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ class Router(formatOps: FormatOps) {
}(nlSplitFunc)
case FormatToken(T.RightBrace(), T.KwElse(), _) =>
val nlOnly = style.newlines.alwaysBeforeElseAfterCurlyIf ||
!leftOwner.is[Term.Block] || !leftOwner.parent.contains(rightOwner)
!leftOwner.is[Term.Block]
Seq(Split(Space.orNL(!nlOnly), 0))

case FormatToken(T.RightBrace(), T.KwYield(), _) => Seq(Split(Space, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,5 @@ rewrite.rules = [RedundantBraces, RedundantParens, AvoidInfix]
===
def primaryConstructor: Option[MemberImpl with Constructor] = if (isClass) constructors find { _.isPrimary } else None
>>>
Idempotency violated
=> Diff (- obtained, + expected)
def primaryConstructor: Option[MemberImpl with Constructor] =
- if (isClass) constructors.find(_.isPrimary) else None
+ if (isClass) constructors.find(_.isPrimary)
+ else None
def primaryConstructor: Option[MemberImpl with Constructor] =
if (isClass) constructors.find(_.isPrimary) else None
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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, 1483317, "total explored")
assertEquals(explored, 1483304, "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 9372a12

Please sign in to comment.