Skip to content

Commit

Permalink
Router: make sure to indent comments after lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 10, 2023
1 parent f758be4 commit 9a43b69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ class FormatOps(

def getRToks = dropWS(function.tokens.reverse)
function.parent match {
case Some(b @ Term.Block(_ :: Nil)) =>
getLastToken(b) -> ExpiresOn.Before
case Some(Term.Block(_ :: Nil)) =>
getLastNonTrivialToken(function) -> ExpiresOn.Before
case Some(Case(_, _, `function`)) =>
orElse(dropComment(getRToks))
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,17 @@ class Router(formatOps: FormatOps) {
) None
else Some(false)
val indents =
Nil
if (nlOnly.contains(false)) {
val beforeClose = tokens.prevNonCommentBefore(closeFT).right
if (beforeClose eq close) Nil
else {
val indent = style.indent.main
List(
Indent(indent, close, Before),
Indent(-indent, beforeClose, Before)
)
}
} else Nil
(expire, arrow.map(_.left), indents, nlOnly)
case Some(t: Case) if t.cond.isEmpty && (leftOwner match {
case Term.PartialFunction(`t` :: Nil) => true
Expand Down
2 changes: 1 addition & 1 deletion scalafmt-tests/src/test/resources/default/Lambda.stat
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,6 @@ object a {
object a {
And("foo") { () =>
baz
// bar
// bar
}
}

0 comments on commit 9a43b69

Please sign in to comment.