Skip to content

Commit

Permalink
RedundantBraces: add parensForOneLineApply flag
Browse files Browse the repository at this point in the history
By default, it's enabled in edition 2020-01, just as before, but can be
disabled if necessary, as has been requested by several users.
  • Loading branch information
kitbellew committed Feb 18, 2020
1 parent 2f3e215 commit 7676259
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ Configuration options and default values:
- `rewrite.redundantBraces.stringInterpolation = true`
- `rewrite.redundantBraces.generalExpressions = false` (disabled by default due
to #1147)
- `rewrite.redundantBraces.parensForOneLineApply`
- by default, `true` in edition 2020-01
- turns `foo { bar => baz }` into `foo(bar => baz)`

### `RedundantParens`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ case class RedundantBracesSettings(
includeUnitMethods: Boolean = true,
maxLines: Int = 100,
stringInterpolation: Boolean = false,
parensForOneLineApply: Option[Boolean] = None,
// Re-enable generalExpressions once
// https://github.com/scalameta/scalafmt/issues/1147 is fixed
generalExpressions: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class FormatWriter(formatOps: FormatOps) {
}
}

if (initStyle.activeForEdition_2020_01 &&
if (initStyle.rewrite.redundantBraces.parensForOneLineApply
.getOrElse(initStyle.activeForEdition_2020_01) &&
initStyle.rewrite.rules.contains(RedundantBraces))
replaceRedundantBraces(result)

Expand Down

0 comments on commit 7676259

Please sign in to comment.