Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolicyOps: move penalizeNewlineByNesting #4026

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,6 @@ class FormatOps(
if (r.is[T.LeftBrace]) SplitTag.OneArgPerLine.activateOnly(s)
else Decision.onlyNewlineSplits(s)

def penalizeNewlineByNesting(from: T, to: T)(implicit
fileLine: FileLine,
): Policy = {
val policy = Policy.before(to) { case Decision(FormatToken(l, _, m), s) =>
val nonBoolPenalty = if (isBoolOperator(l)) 0 else 5
val penalty = nestedSelect(m.leftOwner) + nestedApplies(m.rightOwner) +
nonBoolPenalty
s.map(x => if (x.isNL) x.withPenalty(penalty) else x)
}
new Policy.Delay(policy, Policy.End < from)
}

val WithTemplateOnLeft = new ExtractFromMeta(_.leftOwner match {
case lo: Stat.WithTemplate => Some(lo.templ)
case _ => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ object PolicyOps {
)
}

def penalizeNewlineByNesting(from: T, to: T)(implicit
fileLine: FileLine,
): Policy = {
val policy = Policy.before(to) { case Decision(FormatToken(l, _, m), s) =>
val nonBoolPenalty = if (TokenOps.isBoolOperator(l)) 0 else 5
val penalty = TreeOps.nestedSelect(m.leftOwner) +
TreeOps.nestedApplies(m.rightOwner) + nonBoolPenalty
s.map(x => if (x.isNL) x.withPenalty(penalty) else x)
}
new Policy.Delay(policy, Policy.End < from)
}

/** Forces all splits up to including expire to be on a single line.
* @param okSLC
* if true, allow single-line comments
Expand Down
Loading