Skip to content

Commit

Permalink
RedundantBraces: rename maxLines to maxBreaks
Browse files Browse the repository at this point in the history
In reality, the parameter has always been implemented to constrain the
difference between last line and first line, so calling it `maxLines`
was misleading.
  • Loading branch information
kitbellew committed Jan 5, 2022
1 parent 93e6fe8 commit a95b129
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2525,15 +2525,18 @@ rewrite.redundantBraces.parensForOneLineApply = true
xs.map { x => x + 1 }
```

#### `RedundantBraces`: `maxLines`
#### `RedundantBraces`: `maxBreaks`

This parameter limits the number of line breaks inside the input body. Prior to
v3.3.2, was incorrectly called `maxLines`.

```scala mdoc:defaults
rewrite.redundantBraces.maxLines
rewrite.redundantBraces.maxBreaks
```

```scala mdoc:scalafmt
rewrite.rules = [RedundantBraces]
rewrite.redundantBraces.maxLines = 3
rewrite.redundantBraces.maxBreaks = 3
---
def f() = {
collection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.scalafmt.config

import metaconfig._
import metaconfig.annotation.ExtraName

case class RedundantBracesSettings(
methodBodies: Boolean = true,
includeUnitMethods: Boolean = true,
maxLines: Int = 100,
@ExtraName("maxLines")
maxBreaks: Int = 100,
stringInterpolation: Boolean = false,
parensForOneLineApply: Boolean = true,
generalExpressions: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ object ScalafmtConfig {
addIf(rewrite.insertBraces.minLines != 0 && rewrite.scala3.insertEndMarkerMinLines != 0)
addIf(rewrite.insertBraces.minLines != 0 && rewrite.scala3.removeOptionalBraces == RemoveOptionalBraces.oldSyntaxToo)
if (rewrite.insertBraces.minLines != 0 && rewrite.rules.contains(RedundantBraces))
addIf(rewrite.insertBraces.minLines <= rewrite.redundantBraces.maxLines)
addIf(rewrite.insertBraces.minLines < rewrite.redundantBraces.maxBreaks)
}
// scalafmt: {}
if (allErrors.isEmpty) Configured.ok(cfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
settings.methodBodies && (getTreeSingleStat(b) match {
case Some(_: Term.PartialFunction) => false
case Some(_: Term.Block) => true
case Some(s) => getTreeLineSpan(s) <= settings.maxLines
case Some(s) => getTreeLineSpan(s) <= settings.maxBreaks
case _ => okIfMultipleStats
})

Expand All @@ -466,7 +466,7 @@ class RedundantBraces(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
private def getSingleStatIfLineSpanOk(b: Term.Block)(implicit
style: ScalafmtConfig
): Option[Stat] =
getBlockSingleStat(b).filter(getTreeLineSpan(_) <= settings.maxLines)
getBlockSingleStat(b).filter(getTreeLineSpan(_) <= 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 a95b129

Please sign in to comment.