Skip to content

Commit

Permalink
TokenOps fix: blank line between mod and scaladoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 17, 2020
1 parent a0ba249 commit 48836fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ class Router(formatOps: FormatOps) {
// Inline comment
case FormatToken(left, _: T.Comment, _) =>
val forceBlankLine = formatToken.hasBreak &&
blankLineBeforeDocstring(left, formatToken.meta.right.text)
blankLineBeforeDocstring(formatToken)
val mod = if (forceBlankLine) Newline2x else getMod(formatToken)
Seq(Split(mod, 0))
// Commented out code should stay to the left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,12 @@ object TokenOps {

def blankLineBeforeDocstring(
ft: FormatToken
)(implicit style: ScalafmtConfig): Boolean =
ft.right.is[Token.Comment] &&
blankLineBeforeDocstring(ft.left, ft.meta.right.text)

def blankLineBeforeDocstring(
left: => Token,
right: => String
)(implicit style: ScalafmtConfig): Boolean =
style.optIn.forceNewlineBeforeDocstringSummary &&
!left.is[Token.Comment] && right.startsWith("/**")
ft.right.is[Token.Comment] && !ft.left.is[Token.Comment] &&
ft.meta.right.text.startsWith("/**") &&
!ft.meta.leftOwner.is[meta.Mod] &&
!TreeOps.existsParentOfType[meta.Mod](ft.meta.leftOwner)

// 2.13 implements SeqOps.findLast
def findLast[A](seq: Seq[A])(cond: A => Boolean): Option[A] =
Expand Down
15 changes: 8 additions & 7 deletions scalafmt-tests/src/test/resources/test/JavaDoc.stat
Original file line number Diff line number Diff line change
Expand Up @@ -953,12 +953,13 @@ object a {
class QueueSequentialBenchmark {}
}
>>>
Formatter output does not parse:

object a {
@foo
/**
* scaladoc
*/
^
class QueueSequentialBenchmark {}
}
<<< #2027 2
object a {
@foo(bar)
Expand All @@ -968,12 +969,13 @@ object a {
class QueueSequentialBenchmark {}
}
>>>
Formatter output does not parse:

object a {
@foo(bar)
/**
* scaladoc
*/
^
class QueueSequentialBenchmark {}
}
<<< #2027 3
object a {
private
Expand All @@ -985,7 +987,6 @@ object a {
>>>
object a {
private

/**
* scaladoc
*/
Expand Down

0 comments on commit 48836fd

Please sign in to comment.