Rule request
Thesis
We should support simplifying match statements with only one case and no wildcard:
Example:
match x:
case 1:
do_something()
Can be rewritten as:
if x == 1:
do_something()
Reasoning
Even without an else branch, a single-case match is unnecessarily complex compared to a simple if. The intent is clear, and using if reduces nesting and cognitive load.
This is especially common in validation or dispatch logic where only one condition matters.
When should this be allowed?
Only when:
- There is exactly one case
- The pattern is simple (literal, constant, enum, etc.)
- No guard (
if ...) is used
Originally posted by @sobolevn in #3526 (review)
Rule request
Thesis
We should support simplifying
matchstatements with only one case and no wildcard:Example:
Can be rewritten as:
Reasoning
Even without an else branch, a single-case
matchis unnecessarily complex compared to a simpleif. The intent is clear, and usingifreduces nesting and cognitive load.This is especially common in validation or dispatch logic where only one condition matters.
When should this be allowed?
Only when:
if...) is usedOriginally posted by @sobolevn in #3526 (review)