Skip to content

Commit

Permalink
RedundantBraces: keep if a comment is attached
Browse files Browse the repository at this point in the history
Also, check comments only for scala2.
  • Loading branch information
kitbellew committed Oct 2, 2024
1 parent 50798f3 commit c134faf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,19 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
session: Session,
style: ScalafmtConfig,
): (Replacement, Replacement) = {
@tailrec
def okComment(xft: FormatToken): Boolean =
ftoks.prevNotTrailingComment(xft) match {
case Right(x) =>
if ((x eq xft) && x.hasBreak)
!ftoks.isAttachedCommentThenBreak(ftoks.next(ft))
else !session.isRemovedOnLeft(x, true) || okComment(ftoks.prev(x))
case _ => false
}
val ok = ft.meta.rightOwner match {
case _: Term.Block => ftoks.prevNotTrailingComment(ft).isRight &&
!braceSeparatesTwoXmlTokens &&
case _: Term.Block => !braceSeparatesTwoXmlTokens &&
(style.dialect.allowSignificantIndentation ||
!elseAfterRightBraceThenpOnLeft)
okComment(ft) && !elseAfterRightBraceThenpOnLeft)
case _ => true
}
if (ok) (left, removeToken) else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,11 @@ object a {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
searchIndices()
- // else swallow the termination and wait for pull
+ // else swallow the termination and wait for pull
}
object a {
override def onUpstreamFinish(): Unit =
if (buffer.isEmpty)
completeStage()
else if (isAvailable(out)) {
searchIndices()
} // else swallow the termination and wait for pull
}

0 comments on commit c134faf

Please sign in to comment.