Skip to content

Commit

Permalink
RedundantBraces: extract method checking line span
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Meltzer authored and kitbellew committed Feb 18, 2024
1 parent e186326 commit e6a58f5
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
isDefnBodiesEnabled(noParams = false) && (getTreeSingleStat(b) match {
case Some(_: Term.PartialFunction) => false
case Some(_: Term.Block) => true
case Some(s) => getTreeLineSpan(s) <= settings.maxBreaks
case Some(s) => okLineSpan(s)
case _ => okIfMultipleStats
})

Expand All @@ -545,7 +545,10 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
private def getSingleStatIfLineSpanOk(b: Term.Block)(implicit
style: ScalafmtConfig
): Option[Stat] =
getBlockSingleStat(b).filter(getTreeLineSpan(_) <= settings.maxBreaks)
getBlockSingleStat(b).filter(okLineSpan(_))

private def okLineSpan(tree: Tree)(implicit style: ScalafmtConfig): Boolean =
getTreeLineSpan(tree) <= settings.maxBreaks

// special case for Select which might contain a space instead of dot
private def isPrefixExpr(expr: Tree): Boolean =
Expand Down

0 comments on commit e6a58f5

Please # to comment.