From 51a5a5c9386eb012a146af5d8bd6a5edb61ab06c Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 24 Jun 2020 10:51:20 -0700 Subject: [PATCH] Router: keep blank line in empty case clause body --- .../src/main/scala/org/scalafmt/internal/Router.scala | 10 ++++++---- scalafmt-tests/src/test/resources/default/Case.stat | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 4bb3fc0e37..07db525b44 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -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) => diff --git a/scalafmt-tests/src/test/resources/default/Case.stat b/scalafmt-tests/src/test/resources/default/Case.stat index 437d71e985..48330b7005 100644 --- a/scalafmt-tests/src/test/resources/default/Case.stat +++ b/scalafmt-tests/src/test/resources/default/Case.stat @@ -212,6 +212,7 @@ object a { object a { val a = a match { case a => + case b => } }