Skip to content

Commit

Permalink
Router: keep blank line in empty case clause body
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 24, 2020
1 parent 4fd5b86 commit 51a5a5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,17 @@ class Router(formatOps: FormatOps) {
singleLineSplit +: multiLineSplits

// Case arrow
case tok @ FormatToken(arrow @ T.RightArrow(), right, between)
if leftOwner.isInstanceOf[Case] =>
case tok @ FormatToken(_: T.RightArrow, right, _) if leftOwner.is[Case] =>
val caseStat = leftOwner.asInstanceOf[Case]
if (right.is[T.LeftBrace] && (caseStat.body eq rightOwner))
// Redundant {} block around case statements.
Seq(Split(Space, 0).withIndent(-2, rightOwner.tokens.last, After))
else {
def newlineSplit(cost: Int) =
Split(NewlineT(noIndent = rhsIsCommentedOut(tok)), cost)
def newlineSplit(cost: Int) = {
val noIndent = rhsIsCommentedOut(tok)
val isDouble = tok.hasBlankLine && caseStat.body.tokens.isEmpty
Split(NewlineT(isDouble = isDouble, noIndent = noIndent), cost)
}
def foldedSplits =
caseStat.body match {
case _ if right.is[T.KwCase] || isSingleLineComment(right) =>
Expand Down
1 change: 1 addition & 0 deletions scalafmt-tests/src/test/resources/default/Case.stat
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ object a {
object a {
val a = a match {
case a =>

case b =>
}
}

0 comments on commit 51a5a5c

Please sign in to comment.