Skip to content

Commit

Permalink
RedundantBraces: rename methodBodies to defnBodies
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 5, 2022
1 parent a95b129 commit 741c985
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2460,15 +2460,17 @@ if (a > b) {
}
```

#### `RedundantBraces`: `methodBodies`
#### `RedundantBraces`: `defnBodies`

In v3.3.2, this parameter superseded a boolean `methodBodies`.

```scala mdoc:defaults
rewrite.redundantBraces.methodBodies
rewrite.redundantBraces.defnBodies
```

```scala mdoc:scalafmt
rewrite.rules = [RedundantBraces]
rewrite.redundantBraces.methodBodies = true
rewrite.redundantBraces.defnBodies = true
---
def f() = {
1 + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import metaconfig._
import metaconfig.annotation.ExtraName

case class RedundantBracesSettings(
methodBodies: Boolean = true,
@ExtraName("methodBodies")
defnBodies: Boolean = true,
includeUnitMethods: Boolean = true,
@ExtraName("maxLines")
maxBreaks: Int = 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
!x.tokens.exists(_.is[Token.RightArrow])) =>
removeToken
case t: Ctor.Secondary
if t.stats.isEmpty && style.rewrite.redundantBraces.methodBodies =>
if t.stats.isEmpty && style.rewrite.redundantBraces.defnBodies =>
val prevIsEquals = ftoks.prevNonComment(ft).left.is[Token.Equals]
if (prevIsEquals) removeToken else replaceWithEquals
case _ => null
Expand Down Expand Up @@ -309,7 +309,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
case Type.Name("Unit") => true
case _ => false
}
settings.methodBodies &&
settings.defnBodies &&
checkBlockAsBody(b, d.body) &&
!isProcedureSyntax(d) &&
!disqualifiedByUnit
Expand Down Expand Up @@ -439,7 +439,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
b: Term,
okIfMultipleStats: => Boolean
)(implicit style: ScalafmtConfig): Boolean =
settings.methodBodies && (getTreeSingleStat(b) match {
settings.defnBodies && (getTreeSingleStat(b) match {
case Some(_: Term.PartialFunction) => false
case Some(_: Term.Block) => true
case Some(s) => getTreeLineSpan(s) <= settings.maxBreaks
Expand Down

0 comments on commit 741c985

Please sign in to comment.