Skip to content

Commit

Permalink
Router: attached comment as optimal in def body
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 7, 2020
1 parent ec99c5f commit 46c5ce8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2044,10 +2044,16 @@ class Router(formatOps: FormatOps) {

val expire = body.tokens.last
// rhsOptimalToken is too aggressive here
val optimal = tokens(expire).right match {
case x: T.Comma => x
case x @ RightParenOrBracket() if !wouldDangle => x
case _ => expire
val expireFt = tokens(expire)
val optimalFt = expireFt.right match {
case _: T.Comma => next(expireFt)
case RightParenOrBracket() if !wouldDangle => next(expireFt)
case _ => expireFt
}
val optimal = optimalFt.left
def optimalWithComment = optimalFt.right match {
case x: T.Comment if optimalFt.noBreak => x
case _ => optimalFt.left
}

val penalty = ft.meta.leftOwner match {
Expand Down Expand Up @@ -2082,6 +2088,8 @@ class Router(formatOps: FormatOps) {
case _: Term.Try | _: Term.TryWithHandler =>
// we force newlines in try/catch/finally
Left(Split.ignored)
case t: Term.Apply if t.args.nonEmpty =>
Left(baseSpaceSplit.withOptimalToken(optimalWithComment))
case _ => Right(NoPolicy)
}

Expand Down
8 changes: 3 additions & 5 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1390,14 +1390,12 @@ object a {
)
}
>>>
Idempotency violated
object a {
def i: Item =
i.copy(
name =
b(
c
) // Very long comment here because I need to have more than 80 characters
name = b(
c
) // Very long comment here because I need to have more than 80 characters
)
}
<<< #2175 2 nested assign with apply and long comment
Expand Down

0 comments on commit 46c5ce8

Please sign in to comment.