Skip to content

Commit

Permalink
TreeOps: rename, improve endsWithFewerBraces
Browse files Browse the repository at this point in the history
Exclude expressions enclosed in braces or parens.
  • Loading branch information
kitbellew committed Mar 27, 2024
1 parent 3a32215 commit 08f0a19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class FormatOps(
case x => !isEnclosedInParens(x)
})
val afterInfix = style.breakAfterInfix(t)
if (isBeforeOp && endsWithFewerBraces(app.lhs)) Seq(Split(Newline, 0))
if (isBeforeOp && isFewerBracesLhs(app.lhs)) Seq(Split(Newline, 0))
else if (afterInfix ne Newlines.AfterInfix.keep) {
if (isBeforeOp) Seq(Split(Space, 0))
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,18 +1073,15 @@ object TreeOps {
dialect.allowFewerBraces && ftoks.getHead(tree.argClause).left.is[Colon]

@tailrec
def endsWithFewerBraces(
def isFewerBracesLhs(
tree: Tree
)(implicit dialect: Dialect, ftoks: FormatTokens): Boolean =
tree match {
!ftoks.isEnclosedInMatching(tree) && (tree match {
case t: Term.Apply => isFewerBraces(t)
case t: Term.ApplyInfix =>
t.argClause.values match {
case arg :: Nil => endsWithFewerBraces(arg)
case _ => false
}
case t: Term.ApplyInfix => isFewerBracesLhs(t.argClause)
case Term.ArgClause(arg :: Nil, _) => isFewerBracesLhs(arg)
case _ => false
}
})

def isParentAnApply(t: Tree): Boolean =
t.parent.exists(_.is[Term.Apply])
Expand Down

0 comments on commit 08f0a19

Please sign in to comment.