Skip to content

Commit

Permalink
RedundantBraces: fix removing blocks
Browse files Browse the repository at this point in the history
We continue removing blocks nested within another block, assuming that
at least one outer block is preserved if necessary.

Therefore, before removing an outer block, make sure it doesn't contain
a deeply nested multi-stat expression.
  • Loading branch information
kitbellew committed Feb 2, 2025
1 parent 60baa9b commit 12efb1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,7 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
// can allow if: no ".foo", no "with B", or has braces
!b.parent.is[Term.Select] || t.templ.inits.lengthCompare(1) <= 0 ||
t.templ.body.stats.nonEmpty || t.tokens.last.is[T.RightBrace]
case _: Term => true
case _ => false
case _ => isTreeSingleExpr(s)
}

private def okToRemoveBlockWithinApply(b: Term.Block)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,10 @@ object a {
}
}
>>>
test does not parse: [dialect scala213] illegal start of simple expression
object a {
def foo =
val len = firstColumn + syntax.length; (len, len)
^
}
====== full result: ======
object a {
def foo =
def foo = {
val len = firstColumn + syntax.length; (len, len)
}
}
<<< def body as nested block 2
object a {
Expand All @@ -786,16 +780,10 @@ object a {
}
}
>>>
test does not parse: [dialect scala213] illegal start of simple expression
object a {
def foo =
val len = firstColumn + syntax.length; (len, len)
^
}
====== full result: ======
object a {
def foo =
def foo = {
val len = firstColumn + syntax.length; (len, len)
}
}
<<< def body as nested block 3
object a {
Expand All @@ -804,14 +792,8 @@ object a {
}
}
>>>
test does not parse: [dialect scala213] illegal start of simple expression
object a {
def foo =
val len = firstColumn + syntax.length; (len, len)
^
}
====== full result: ======
object a {
def foo =
def foo = {
val len = firstColumn + syntax.length; (len, len)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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, 2519892, "total explored")
assertEquals(explored, 2520060, "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 12efb1c

Please sign in to comment.