diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 849da5f068..23006396af 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -1401,6 +1401,7 @@ class Router(formatOps: FormatOps) { if (binPack eq BinPack.Site.Never) None else Some { val lastFT = getLast(nextArg) + val lastTok = lastFT.left val loEnd = leftOwner.tokens.last.end val oneline = binPack == BinPack.Site.Oneline val nextCommaOrParen = findFirst(lastFT, loEnd) { @@ -1434,10 +1435,10 @@ class Router(formatOps: FormatOps) { case _ if callSite => def delayBreakBefore(token: T): Policy = { // force break if multiline and if there's no other break - val lastEnd = lastFT.left.end - delayedBreakPolicy(Policy.End > lastEnd)( + val lastEnd = lastTok.end + delayedBreakPolicy(Policy.End == lastEnd)( Policy.RelayOnSplit { case (s, nextft) => - s.isNL && nextft.left.end > lastEnd // don't need anymore + s.isNL && nextft.right.end > lastEnd // don't need anymore }(decideNewlinesOnlyBeforeToken(token), NoPolicy), ) } @@ -1461,7 +1462,7 @@ class Router(formatOps: FormatOps) { val indentOncePolicy = Policy ? (callSite && style.binPack.indentCallSiteOnce) && { val trigger = getIndentTrigger(leftOwner) - Policy.on(lastFT.left, prefix = "IND1") { + Policy.on(lastTok, prefix = "IND1") { case Decision(FormatToken(LeftParenOrBracket(), _, m), s) if isArgClauseSite(m.leftOwner) => s.map(x => if (x.isNL) x else x.switch(trigger, true)) diff --git a/scalafmt-tests/src/test/resources/scalajs/Apply.stat b/scalafmt-tests/src/test/resources/scalajs/Apply.stat index 1968da5460..04edf46689 100644 --- a/scalafmt-tests/src/test/resources/scalajs/Apply.stat +++ b/scalafmt-tests/src/test/resources/scalajs/Apply.stat @@ -1023,8 +1023,7 @@ object a { js.MethodDef(flags, methodIdent, originalName, jsParams, resultType, Some { genApplyMethod(genLoadModule(moduleClass), m, jsParams.map(_.ref)) - })( - OptimizerHints.empty, Unversioned) + })(OptimizerHints.empty, Unversioned) } <<< nested with oneline, keep newlines.source = keep @@ -1042,8 +1041,7 @@ object a { js.MethodDef(flags, methodIdent, originalName, jsParams, resultType, Some { genApplyMethod(genLoadModule(moduleClass), m, jsParams.map(_.ref)) - })( - OptimizerHints.empty, Unversioned) + })(OptimizerHints.empty, Unversioned) } <<< oneline with keep and select after preset = default @@ -1068,7 +1066,6 @@ object a { js.Dynamic.literal( `type` = "button", value = "Reset" - )) - .click(() => reset()) + )).click(() => reset()) } }