diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala index 166c28e008..6bd40030a9 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala @@ -428,19 +428,18 @@ class RedundantBraces(implicit val ftoks: FormatTokens) (plo eq t) || !plo.parent.contains(t) case _ => true }) && - (style.dialect.allowSignificantIndentation || - (t.parent match { - case Some(_: Term.Block) => true - case Some(_: Term.ArgClause) => - val pft = ftoks.prevNonComment(left.ft) - pft.left match { - case _: T.LeftParen => - isLeftParenReplacedWithBraceOnLeft(pft) - case _: T.LeftBrace => true - case _ => false - } - case _ => false - }) || okComment(ft) && !elseAfterRightBraceThenpOnLeft) => + ((t.parent match { + case Some(_: Term.Block) => true + case Some(_: Term.ArgClause) => + val pft = ftoks.prevNonComment(left.ft) + pft.left match { + case _: T.LeftParen => + isLeftParenReplacedWithBraceOnLeft(pft) + case _: T.LeftBrace => true + case _ => false + } + case _ => style.dialect.allowSignificantIndentation + }) || okComment(ft) && !elseAfterRightBraceThenpOnLeft) => (left, removeToken) case ReplacementType.Replace if left.ft.right.is[T.LeftParen] => left -> replaceTokenBy(")", t.parent)(x => diff --git a/scalafmt-tests/shared/src/test/resources/rewrite/RedundantBraces2.stat b/scalafmt-tests/shared/src/test/resources/rewrite/RedundantBraces2.stat index 8e3398f687..3ad0c65994 100644 --- a/scalafmt-tests/shared/src/test/resources/rewrite/RedundantBraces2.stat +++ b/scalafmt-tests/shared/src/test/resources/rewrite/RedundantBraces2.stat @@ -682,3 +682,82 @@ class SampleSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers { it should "be formatted correctly, too" in IO(2).asserting(_ shouldBe 2) } +<<< #4731 scala3 with end marker +runner.dialect = scala3 +rewrite.scala3.removeOptionalBraces = yes +rewrite.scala3.insertEndMarkerMinLines = 1 +=== +object a: + def readRawVarint32(input: InputStream): Int = { + { + val firstByte = input.read() + if (firstByte == -1) { + throw InvalidProtocolBufferException.truncatedMessage() + } + readRawVarint32(firstByte, input) + } //todo: labels is not supported + } +>>> +object a: + def readRawVarint32(input: InputStream): Int = + val firstByte = input.read() + if (firstByte == -1) { + throw InvalidProtocolBufferException.truncatedMessage() + } + readRawVarint32(firstByte, input) + // todo: labels is not supported + end readRawVarint32 +<<< #4731 scala2 +runner.dialect = scala213 +=== +"Service" must { + "have at least one test" in { + pending + // Write here your test .... + // don't forget to remove `pending` + } +} +>>> +"Service" must { + "have at least one test" in { + pending + // Write here your test .... + // don't forget to remove `pending` + } +} +<<< #4731 scala3 +runner.dialect = scala3 +=== +"Service" must { + "have at least one test" in { + pending + // Write here your test .... + // don't forget to remove `pending` + } +} +>>> +"Service" must { + "have at least one test" in { + pending + // Write here your test .... + // don't forget to remove `pending` + } +} +<<< #4731 scala3 coloneol +runner.dialect = scala3 +=== +"Service" must { + "have at least one test" in: + { + pending + // Write here your test .... + // don't forget to remove `pending` + } +} +>>> +"Service" must { + "have at least one test" in: + pending + // Write here your test .... + // don't forget to remove `pending` +} diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index f640125711..ce2d22e4d1 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -144,7 +144,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, 1258776, "total explored") + assertEquals(explored, 1258958, "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 :'(