Skip to content

Commit

Permalink
Define flag removeOptionalBraces.fewerParensToo
Browse files Browse the repository at this point in the history
Also test apply with parens to be rewritten to fewer-braces.
  • Loading branch information
kitbellew committed Nov 7, 2024
1 parent 504a8fa commit b3c48d4
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,11 @@ The section contains the following settings (available since v3.8.1):
- will only apply the rewrite if the cumulative span of all visible
(non-whitespace) tokens within the argument is between the two values
- this rule is disabled if `fewerBracesMaxSpan == 0`
- (since v3.8.4) `fewerBracesParensToo`
- will apply the rule just above to an argument in parentheses as well,
if the one of following is also satisfied:
- [`newlines.afterInfix`](#newlinesafterinfix) is NOT `keep`; or
- current dialect supports `allowInfixOperatorAfterNL`

Prior to v3.8.1, `rewrite.scala3.removeOptionalBraces` was a flag which
took three possible values (with their equivalent current settings shown):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ object RewriteScala3Settings {
enabled: Boolean = true,
fewerBracesMinSpan: Int = 2,
fewerBracesMaxSpan: Int = 0,
fewerBracesParensToo: Boolean = false,
oldSyntaxToo: Boolean = false,
)

Expand Down
19 changes: 19 additions & 0 deletions scalafmt-tests/shared/src/test/resources/scala3/FewerBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,22 @@ object a:
x + 2
x + 3
}
<<< single arg with parens
rewrite.scala3.removeOptionalBraces {
enabled = yes
fewerBracesMinSpan = 1
fewerBracesMaxSpan = 10
fewerBracesParensToo = true
}
===
object a:
println(
a
+ b
)
>>>
object a:
println(
a
+ b
)
Original file line number Diff line number Diff line change
Expand Up @@ -2028,3 +2028,19 @@ object a:
x + 2
x + 3
}
<<< single arg with parens
rewrite.scala3.removeOptionalBraces {
enabled = yes
fewerBracesMinSpan = 1
fewerBracesMaxSpan = 10
fewerBracesParensToo = true
}
===
object a:
println(
a
+ b
)
>>>
object a:
println(a + b)
Original file line number Diff line number Diff line change
Expand Up @@ -2275,3 +2275,22 @@ object a:
x + 2
x + 3
}
<<< single arg with parens
rewrite.scala3.removeOptionalBraces {
enabled = yes
fewerBracesMinSpan = 1
fewerBracesMaxSpan = 10
fewerBracesParensToo = true
}
===
object a:
println(
a
+ b
)
>>>
object a:
println(
a
+ b
)
Original file line number Diff line number Diff line change
Expand Up @@ -2308,3 +2308,19 @@ object a:
x + 2
x + 3
}
<<< single arg with parens
rewrite.scala3.removeOptionalBraces {
enabled = yes
fewerBracesMinSpan = 1
fewerBracesMaxSpan = 10
fewerBracesParensToo = true
}
===
object a:
println(
a
+ b
)
>>>
object a:
println(a + b)
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1502182, "total explored")
assertEquals(explored, 1502266, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down

0 comments on commit b3c48d4

Please sign in to comment.