diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TokenOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TokenOps.scala index a4a7380e6c..a261a68614 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TokenOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TokenOps.scala @@ -1,7 +1,7 @@ package org.scalafmt.util import scala.meta.classifiers.Classifier -import scala.meta.{Defn, Pkg, Template, Tree} +import scala.meta.{Defn, Pkg, Source, Template, Term, Tree} import scala.meta.tokens.Token import scala.meta.tokens.Token._ import scala.meta.tokens.Tokens @@ -54,8 +54,13 @@ object TokenOps { style.optIn.forceNewlineBeforeDocstringSummary && 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) + TreeOps + .findTreeOrParent(ft.meta.leftOwner) { + case _: Pkg | _: Source | _: Template | _: Term.Block => Some(false) + case t if t.pos.end > ft.right.start => Some(true) + case _ => None + } + .isEmpty // 2.13 implements SeqOps.findLast def findLast[A](seq: Seq[A])(cond: A => Boolean): Option[A] = diff --git a/scalafmt-tests/src/test/resources/test/JavaDoc.stat b/scalafmt-tests/src/test/resources/test/JavaDoc.stat index 5f17e4052f..e4e1543656 100644 --- a/scalafmt-tests/src/test/resources/test/JavaDoc.stat +++ b/scalafmt-tests/src/test/resources/test/JavaDoc.stat @@ -1272,7 +1272,6 @@ object Day extends Enumeration { type Day = Value val - /** Monday */ MON = Value }