astral-sh / astral-sh/ruff

new rule - useless if statement

Open
#9,767 4 comments 5 reactions 0 assignees View on GitHub
rule
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

ruff should be able to detect if the code on both sides of an if statement are identical, and report it as unnecessary
```py
if 1: # error: both sides of the if statement are the same
print(1)
else:
print(1)

asdf = 1 if bool() else 1 # error: both sides of the if expression are the same
```

Contributor guide

Open the contributing guide

Research direction

No file or test is named in the issue. Start by locating Ruff's existing rules and tests for redundant branches or conditional expressions, then use both provided Python examples as regression cases; done means identical if branches and conditional-expression arms are reported as unnecessary.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.