Skip to content

Commit

Permalink
FormatOps: keep newline after comment in body
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 9, 2021
1 parent 88ddbfd commit 89099e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1807,11 +1807,12 @@ class FormatOps(
nlSplitFunc: Int => Split
)(splitsFunc: FormatToken => Seq[Split]): Seq[Split] =
if (!ft.right.is[T.Comment]) splitsFunc(ft)
else if (ft.hasBreak || isSingleLineComment(ft.right))
Seq(nlSplitFunc(0).forThisLine)
else if (ft.hasBreak) Seq(nlSplitFunc(0).forThisLine)
else {
val nextFt = nextNonCommentSameLine(next(ft))
val splits = splitsFunc(nextFt)
val splits =
if (nextFt.noBreak) splitsFunc(nextFt)
else Seq(nlSplitFunc(0).forThisLine)
val policy = Policy.on(nextFt.right) { case Decision(`nextFt`, _) =>
splits
}
Expand Down
3 changes: 2 additions & 1 deletion scalafmt-tests/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,8 @@ object a {
>>>
object a {
def validate(d: DirectoryProxy, step: Int): Unit =
if (step != 0) /* c1 */ d.name should be("dir" + step)
if (step != 0) /* c1 */
d.name should be("dir" + step)
}
<<< #2113 def 4
object a {
Expand Down

0 comments on commit 89099e3

Please sign in to comment.