wemake-python-styleguide
wemake-python-styleguide copied to clipboard
feat: add SimplifiableIfMatchViolation for single-case matches
Overview
This PR adds a new violation SimplifiableIfMatchViolation that flags single-case match statements that can be simplified to if statements. This helps reduce unnecessary complexity and cognitive load when a simple if condition would suffice.
Checklist
- [x] Code changes implemented
- [x] Tests added for new violation
- [x] Documentation included in violation docstring
Proof
The new violation is tested with various cases in test_simplified_match_conditions.py:
- Single-case matches with simple literals (e.g.,
case 1:,case True:,case "string":) trigger the violation - Single-case matches with as-binding also trigger the violation
- Multi-case matches, matches with guards, wildcard cases, and complex patterns do not trigger the violation
- The violation correctly identifies when a single-case match can be simplified to an if statement
Closes #3528