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 15, 2023
1 parent 2d87477 commit aadca03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ class Router(formatOps: FormatOps) {
StartsStatementRight(stmt)
) if leftOwner.isInstanceOf[Term.FunctionTerm] =>
val leftFuncBody = leftOwner.asInstanceOf[Term.FunctionTerm].body
val endOfFunction = getLastNonTrivialToken(leftFuncBody)
val endOfFunction = getLastNonTrivial(leftFuncBody)
val endIndent = leftOwner.parent match {
case Some(Term.Block(_ :: Nil)) => nextNonComment(endOfFunction).left
case _ => endOfFunction.left
}
val canBeSpace = stmt.isInstanceOf[Term.FunctionTerm]
val (afterCurlySpace, afterCurlyNewlines) =
getSpaceAndNewlineAfterCurlyLambda(newlines)
Expand All @@ -432,14 +436,14 @@ class Router(formatOps: FormatOps) {
(!rightOwner.is[Defn] || style.newlines.source.eq(Newlines.fold))
)
Split(Space, 0).withSingleLineNoOptimal(
getOptimalTokenFor(endOfFunction),
getOptimalTokenFor(endOfFunction.left),
noSyntaxNL = true
)
else Split.ignored
Seq(
spaceSplit,
Split(afterCurlyNewlines, 1)
.withIndent(style.indent.main, endOfFunction, After)
.withIndent(style.indent.main, endIndent, After)
)

case FormatToken(T.RightArrow() | T.ContextArrow(), right, _)
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 aadca03

Please sign in to comment.