Skip to content

Commit

Permalink
Newlines: break before params of multiline lambda
Browse files Browse the repository at this point in the history
This option allows forgoing the break for oneline formatting, which the
`always` option doesn't provide.
  • Loading branch information
kitbellew committed Sep 12, 2020
1 parent 199c0a3 commit 36a7399
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ class Router(formatOps: FormatOps) {
case Some(owner: Term.Function) =>
val arrow = getFuncArrow(lastLambda(owner))
val expire = arrow.getOrElse(tokens(owner.tokens.last))
val nlOnly = Some(style.newlines.alwaysBeforeCurlyLambdaParams)
val nlOnly =
if (style.newlines.alwaysBeforeCurlyLambdaParams) Some(true)
else if (
style.newlines.beforeCurlyLambdaParams eq
Newlines.BeforeCurlyLambdaParams.multiline
) None
else Some(false)
(expire, arrow.map(_.left), 0, nlOnly)
case Some(t: Case) if t.cond.isEmpty && (leftOwner match {
case Term.PartialFunction(List(`t`)) => true
Expand All @@ -206,8 +212,8 @@ class Router(formatOps: FormatOps) {
val nlOnly =
if (style.newlines.alwaysBeforeCurlyLambdaParams) Some(true)
else if (
style.newlines.beforeCurlyLambdaParams eq
Newlines.BeforeCurlyLambdaParams.multilineWithCaseOnly
style.newlines.beforeCurlyLambdaParams ne
Newlines.BeforeCurlyLambdaParams.never
) None
else Some(false)
(arrow, Some(arrow.left), 0, nlOnly)
Expand Down
13 changes: 7 additions & 6 deletions scalafmt-tests/src/test/resources/unit/Lambda.stat
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,15 @@ object a {
object a {
x.map { x => s"${x._1} -> ${x._2}" }
x.map { case (c, i) => s"$c -> $i" }
x.zipWithIndex.map { x =>
s"${x._1} -> ${x._2}"
x.zipWithIndex.map {
x => s"${x._1} -> ${x._2}"
}
x.zipWithIndex.map { case (c, i) =>
s"$c -> $i"
x.zipWithIndex.map {
case (c, i) => s"$c -> $i"
}
x.zipWithIndex.map { case (c, i) =>
s"$c -> $i (long comment)"
x.zipWithIndex.map {
case (c, i) =>
s"$c -> $i (long comment)"
}
x.zipWithIndex.map {
case (c, i) if c != i =>
Expand Down

0 comments on commit 36a7399

Please sign in to comment.