Skip to content

Conversation

@SoulSniper1212
Copy link

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

  • Code changes implemented
  • Tests added for new violation
  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer if over match with single-case

1 participant