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

FormatOps: refactor getting else chain #3579

Merged
merged 1 commit into from
Jul 7, 2023
Merged
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 @@ -427,13 +427,16 @@ class FormatOps(

@tailrec
private final def getElseChain(term: Term.If, res: Seq[T]): Seq[T] = {
term.tokens.find(x => x.is[T.KwElse] && owners(x) == term) match {
case Some(els @ T.KwElse()) =>
val tuck = !initStyle.newlines.alwaysBeforeElseAfterCurlyIf && {
val prev = tokens(els, -1)
prev.left.is[T.RightBrace] && prev.meta.leftOwner != term
tokens.getHeadOpt(term.elsep) match {
case Some(ftElsep) =>
val beforeElsep = prevNonCommentBefore(ftElsep)
val newRes = beforeElsep.left match {
case els: T.KwElse
if initStyle.newlines.alwaysBeforeElseAfterCurlyIf ||
!prev(beforeElsep).left.is[T.RightBrace] =>
els +: res
case _ => res
}
val newRes = if (tuck) res else els +: res
term.elsep match {
case t: Term.If => getElseChain(t, newRes)
case _ => newRes
Expand Down