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

RemoveScala3OptionalBraces: not match if infix lhs #3573

Merged
merged 2 commits into from
Jul 5, 2023
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 @@ -53,7 +53,8 @@ private class RemoveScala3OptionalBraces(ftoks: FormatTokens)
} =>
removeToken
case _: Term.ForYield => removeToken
case _: Term.Match => removeToken
case t: Term.Match if t.parent.exists(_.isNot[Term.ApplyInfix]) =>
removeToken
case _: Type.Match => removeToken
case _: Term.Try => removeToken
case _: Ctor.Secondary
Expand Down
39 changes: 39 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/Match.stat
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,42 @@ case head :: tail =>
)
case Nil => Nil
}
<<< match as infix lhs, with rewrite
rewrite.scala3.removeOptionalBraces = yes
===
def foo(url: String) = {
url match {
case "foo" => Some("")
case _ => None
} map { img =>
Html(s"""<img class="embed" src="$img" alt="$url"/>""")
}
}
>>>
def foo(url: String) =
url match {
case "foo" => Some("")
case _ => None
} map { img =>
Html(s"""<img class="embed" src="$img" alt="$url"/>""")
}
<<< match as select lhs, with rewrite
rewrite.scala3.removeOptionalBraces = yes
===
def foo(url: String) = {
url.match {
case "foo" => Some("")
case _ => None
}.map { img =>
Html(s"""<img class="embed" src="$img" alt="$url"/>""")
}
}
>>>
def foo(url: String) =
url
.match
case "foo" => Some("")
case _ => None
.map { img =>
Html(s"""<img class="embed" src="$img" alt="$url"/>""")
}
Loading