Skip to content

Commit

Permalink
Router: align costs to ignore current break
Browse files Browse the repository at this point in the history
Otherwise, this might potentially lead to non-idempotent formatting as
costs in subsequent attempts might be different.
  • Loading branch information
kitbellew committed Aug 13, 2024
1 parent 509b980 commit 798cff7
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,8 @@ class Router(formatOps: FormatOps) {
singleLineSplit,
Split(nl, 1).withPolicy(newlineBeforeClosingCurly)
.withIndent(style.indent.main, close, Before),
Split(Space, 0)
Split(style.newlines.keepBreak(newlines), 0)(Space)
.onlyIf(lambdaNLOnly.contains(false) && lambdaPolicy != null)
.notIf(style.newlines.keepBreak(newlines))
.withOptimalTokenOpt(lambdaArrow)
.withIndent(lambdaIndent, close, Before).withPolicy(lambdaPolicy),
)
Expand Down Expand Up @@ -870,7 +869,8 @@ class Router(formatOps: FormatOps) {
implicit val clauseSiteFlags = ClauseSiteFlags(leftOwner, defnSite)
implicit val configStyleFlags = clauseSiteFlags.configStyle
val closeBreak = beforeClose.hasBreak
val onlyConfigStyle = mustForceConfigStyle(ft) ||
val forceConfigStyle = mustForceConfigStyle(ft)
val onlyConfigStyle = forceConfigStyle ||
preserveConfigStyle(ft, mustDangleForTrailingCommas || closeBreak)
val configStyleFlag = configStyleFlags.prefer

Expand Down Expand Up @@ -1059,7 +1059,7 @@ class Router(formatOps: FormatOps) {
) Seq.empty
else {
val cost =
if (onlyConfigStyle) if (splitsNoNL.isEmpty) 0 else 1
if (forceConfigStyle) if (splitsNoNL.isEmpty) 0 else 1
else (if (preferNoSplit) Constants.ExceedColumnPenalty else 0) +
bracketCoef * (nestedPenalty + (if (multipleArgs) 2 else 0))
val split =
Expand Down Expand Up @@ -1690,7 +1690,7 @@ class Router(formatOps: FormatOps) {
// when the flag is on, penalize break, to avoid idempotence issues;
// otherwise, after the break is chosen, the flag prohibits nosplit
val nlBaseCost =
if (style.optIn.breakChainOnFirstMethodDot && noBreak) 3 else 2
if (style.optIn.breakChainOnFirstMethodDot) 3 else 2
val nlCost = nlBaseCost + nestedPenalty + chainLengthPenalty
val nlMod = getNlMod
Seq(
Expand Down

0 comments on commit 798cff7

Please sign in to comment.