Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedundantBraces: fix removing blocks #4783

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -761,3 +761,39 @@ runner.dialect = scala3
// Write here your test ....
// don't forget to remove `pending`
}
<<< def body as nested block 1
object a {
def foo = {
{ val len = firstColumn + syntax.length; (len, len) }
}
}
>>>
object a {
def foo = {
val len = firstColumn + syntax.length; (len, len)
}
}
<<< def body as nested block 2
object a {
def foo = {
{ { val len = firstColumn + syntax.length; (len, len) } }
}
}
>>>
object a {
def foo = {
val len = firstColumn + syntax.length; (len, len)
}
}
<<< def body as nested block 3
object a {
def foo = {
{ { { val len = firstColumn + syntax.length; (len, len) } } }
}
}
>>>
object a {
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, 2519748, "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