Skip to content

Commit

Permalink
Insert newline for else keyword, fixes #1509. (#1520)
Browse files Browse the repository at this point in the history
Insert newline for else keyword, fixes #1509.
  • Loading branch information
olafurpg authored Oct 8, 2019
2 parents ba6ebc3 + 9c26032 commit fea0efc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,8 @@ class Router(formatOps: FormatOps) {
)
case FormatToken(RightBrace(), KwElse(), _) =>
if (style.newlines.alwaysBeforeElseAfterCurlyIf) Seq(Split(Newline, 0))
else Seq(Split(Space, 0))
else if (leftOwner.is[Term.Block]) Seq(Split(Space, 0))
else Seq(Split(Newline, 1))
case FormatToken(RightBrace(), KwYield(), _) =>
Seq(
Split(Space, 0)
Expand Down
21 changes: 21 additions & 0 deletions scalafmt-tests/src/test/resources/test/Issue1509.stat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
maxColumn=41
<<< issue 1509
val x =
if (true)
List() match {
case x :: xs => ???
case Nil => ???
}
else {
2
}
>>>
val x =
if (true)
List() match {
case x :: xs => ???
case Nil => ???
}
else {
2
}

0 comments on commit fea0efc

Please sign in to comment.