diff --git a/docs/configuration.md b/docs/configuration.md index 05db3665d6..0d6f284438 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3025,6 +3025,9 @@ The rule takes the following parameters under `rewrite.avoidInfix`: be excluded - (since 3.8.4) `excludePostfix`, unless set to `true` explicitly, will also apply the rule to `Term.Select` trees specified without a dot +- (since 3.8.4) `excludeMatch`, unless set to `true` explicitly, will also + apply the rule to `Term.Match` trees specified without a dot, if the dialect + enables `allowMatchAsOperator` (such as Scala 3) ```scala mdoc:scalafmt rewrite.rules = [AvoidInfix] @@ -5142,6 +5145,7 @@ object A { This option will enforce a break before each parent. As usual, the break is only actually introduced if indented position on the next line is less than the current. +Added in 3.8.4. ```scala mdoc:scalafmt binPack.parentConstructors = ForceBreak diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/AvoidInfixSettings.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/AvoidInfixSettings.scala index 30d1dae1e4..70ae77ad21 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/AvoidInfixSettings.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/AvoidInfixSettings.scala @@ -14,6 +14,7 @@ case class AvoidInfixSettings( private val excludeScalaTest: Option[Boolean] = None, excludePlaceholderArg: Option[Boolean] = None, excludePostfix: Boolean = false, + excludeMatch: Boolean = false, ) { // if the user completely redefined (rather than appended), we don't touch @inline diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat index 117c6d8c8d..a4fc2f7fc4 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat @@ -7564,8 +7564,9 @@ object Build: } }.evaluated ) -<<< AvoidInfix with match +<<< AvoidInfix with match, excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { a b c match @@ -7576,8 +7577,22 @@ object a { a.b(c) match case _ => } -<<< AvoidInfix with match within applyinfix +<<< AvoidInfix with match, !excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a b c match + case _ => +} +>>> +object a { + a.b(c) match + case _ => +} +<<< AvoidInfix with match within applyinfix, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { a b c match { @@ -7590,8 +7605,38 @@ object a { case _ => }).d(e) } -<<< AvoidInfix with match, with dot +<<< AvoidInfix with match within applyinfix, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a b c match { + case _ => + } d e +} +>>> +object a { + (a.b(c) match { + case _ => + }).d(e) +} +<<< AvoidInfix with match, with dot, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + (a.b(c)).match + case _ => +} +>>> +object a { + (a.b(c)) + .match + case _ => +} +<<< AvoidInfix with match, with dot, !excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false === object a { (a.b(c)).match @@ -7603,6 +7648,32 @@ object a { .match case _ => } +<<< AvoidInfix with match, with annotation, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} +<<< AvoidInfix with match, with annotation, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} <<< match with dot, trailing case comment object a: b.c.match diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat index ed8f22d5a1..1fe09931df 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat @@ -7275,8 +7275,9 @@ object Build: config: GenerationConfig => config.remove[SiteRoot] } }.evaluated) -<<< AvoidInfix with match +<<< AvoidInfix with match, excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { a b c match @@ -7287,8 +7288,35 @@ object a { a.b(c) match case _ => } -<<< AvoidInfix with match within applyinfix +<<< AvoidInfix with match, !excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a b c match + case _ => +} +>>> +object a { + a.b(c) match + case _ => +} +<<< AvoidInfix with match within applyinfix, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + a b c match { + case _ => + } d e +} +>>> +object a { + (a.b(c) match { case _ => }).d(e) +} +<<< AvoidInfix with match within applyinfix, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false === object a { a b c match { @@ -7299,8 +7327,9 @@ object a { object a { (a.b(c) match { case _ => }).d(e) } -<<< AvoidInfix with match, with dot +<<< AvoidInfix with match, with dot, excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { (a.b(c)).match @@ -7311,6 +7340,45 @@ object a { (a.b(c)).match case _ => } +<<< AvoidInfix with match, with dot, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + (a.b(c)).match + case _ => +} +>>> +object a { + (a.b(c)).match + case _ => +} +<<< AvoidInfix with match, with annotation, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} +<<< AvoidInfix with match, with annotation, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} <<< match with dot, trailing case comment object a: b.c.match diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat index 7c8601f8d4..4e4a4829c5 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat @@ -7592,8 +7592,9 @@ object Build: } }.evaluated ) -<<< AvoidInfix with match +<<< AvoidInfix with match, excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { a b c match @@ -7604,8 +7605,22 @@ object a { a.b(c) match case _ => } -<<< AvoidInfix with match within applyinfix +<<< AvoidInfix with match, !excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a b c match + case _ => +} +>>> +object a { + a.b(c) match + case _ => +} +<<< AvoidInfix with match within applyinfix, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { a b c match { @@ -7618,8 +7633,24 @@ object a { case _ => }).d(e) } -<<< AvoidInfix with match, with dot +<<< AvoidInfix with match within applyinfix, !excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a b c match { + case _ => + } d e +} +>>> +object a { + (a.b(c) match { + case _ => + }).d(e) +} +<<< AvoidInfix with match, with dot, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { (a.b(c)).match @@ -7630,6 +7661,45 @@ object a { (a.b(c)).match case _ => } +<<< AvoidInfix with match, with dot, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + (a.b(c)).match + case _ => +} +>>> +object a { + (a.b(c)).match + case _ => +} +<<< AvoidInfix with match, with annotation, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} +<<< AvoidInfix with match, with annotation, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} <<< match with dot, trailing case comment object a: b.c.match diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat index fd57e5dc80..aad697be7b 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -7879,8 +7879,9 @@ object Build: } .evaluated ) -<<< AvoidInfix with match +<<< AvoidInfix with match, excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { a b c match @@ -7891,8 +7892,39 @@ object a { a.b(c) match case _ => } -<<< AvoidInfix with match within applyinfix +<<< AvoidInfix with match, !excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a b c match + case _ => +} +>>> +object a { + a.b(c) match + case _ => +} +<<< AvoidInfix with match within applyinfix, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + a b c match { + case _ => + } d e +} +>>> +object a { + ( + a.b(c) match { + case _ => + } + ).d(e) +} +<<< AvoidInfix with match within applyinfix, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false === object a { a b c match { @@ -7907,8 +7939,9 @@ object a { } ).d(e) } -<<< AvoidInfix with match, with dot +<<< AvoidInfix with match, with dot, excludeMatch rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true === object a { (a.b(c)).match @@ -7919,6 +7952,45 @@ object a { (a.b(c)).match case _ => } +<<< AvoidInfix with match, with dot, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + (a.b(c)).match + case _ => +} +>>> +object a { + (a.b(c)).match + case _ => +} +<<< AvoidInfix with match, with annotation, excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = true +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} +<<< AvoidInfix with match, with annotation, !excludeMatch +rewrite.rules = [AvoidInfix] +rewrite.avoidInfix.excludeMatch = false +=== +object a { + a(b): @c match + case _ => +} +>>> +object a { + a(b): @c match + case _ => +} <<< match with dot, trailing case comment object a: b.c.match 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 fe052f8673..27176d530b 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, 1083760, "total explored") + assertEquals(explored, 1084554, "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 :'(