Skip to content

Commit

Permalink
AvoidInfixSetttings: add excludeMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 20, 2024
1 parent cda5a2f commit 418f7f7
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, if set to `false` explicitly and if the dialect
enables `allowMatchAsOperator` (such as Scala 3), will also apply the rule to
`Term.Match` trees specified without a dot

```scala mdoc:scalafmt
rewrite.rules = [AvoidInfix]
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ case class AvoidInfixSettings(
private val excludeScalaTest: Option[Boolean] = None,
excludePlaceholderArg: Option[Boolean] = None,
excludePostfix: Boolean = false,
excludeMatch: Boolean = true,
) {
// if the user completely redefined (rather than appended), we don't touch
@inline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 418f7f7

Please sign in to comment.