Skip to content

Commit

Permalink
RedundantBraces: refactor body checking
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 23, 2024
1 parent 03244ed commit 72f7024
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,17 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
case Type.Name("Unit") => true
case _ => false
}
checkBlockAsBody(b, d.body, noParams(d.paramClauseGroup)) &&
checkBlockAsBody(b, d.body, noParams = d.paramClauseGroups.isEmpty) &&
!isProcedureSyntax(d) && !disqualifiedByUnit

case d: Defn.Var => d.rhs.exists(checkBlockAsBody(b, _, noParams = true))
case d: Defn.Var => checkBlockAsBody(b, d.body, noParams = true)
case d: Defn.Val => checkBlockAsBody(b, d.rhs, noParams = true)
case d: Defn.Type =>
checkBlockAsBody(b, d.body, noParams = d.tparamClause.values.isEmpty)
checkBlockAsBody(b, d.body, noParams = d.tparamClause.isEmpty)
case d: Defn.Macro =>
checkBlockAsBody(b, d.body, noParams(d.paramClauseGroup))
checkBlockAsBody(b, d.body, noParams = d.paramClauseGroups.isEmpty)
case d: Defn.GivenAlias =>
checkBlockAsBody(b, d.body, noParams(d.paramClauseGroup))
checkBlockAsBody(b, d.body, noParams = d.paramClauseGroup.isEmpty)

case p: Term.FunctionTerm if isFunctionWithBraces(p) =>
okToRemoveAroundFunctionBody(b, true)
Expand Down Expand Up @@ -435,12 +435,6 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
case RedundantBracesSettings.DefnBodies.noParams => noParams
}

private def noParams(group: Member.ParamClauseGroup): Boolean =
group.tparamClause.values.isEmpty && group.paramClauses.isEmpty

private def noParams(group: Option[Member.ParamClauseGroup]): Boolean = group
.forall(noParams)

private def innerOk(b: Term.Block)(s: Stat): Boolean = s match {
case t: Term.NewAnonymous =>
// can't allow: new A with B .foo
Expand Down

0 comments on commit 72f7024

Please sign in to comment.