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

new rule - useless if statement/expression #9767

Open
DetachHead opened this issue Feb 2, 2024 · 1 comment
Open

new rule - useless if statement/expression #9767

DetachHead opened this issue Feb 2, 2024 · 1 comment
Labels
rule Implementing or modifying a lint rule

Comments

@DetachHead
Copy link

DetachHead commented Feb 2, 2024

ruff should be able to detect if the code on both sides of an if statement are identical, and report it as unnecessary

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
@sanxiyn
Copy link
Contributor

sanxiyn commented Feb 2, 2024

This is similar to if-with-same-arms (SIM114) in flake8-simplify, so I filed a rule request upstream: MartinThoma/flake8-simplify#192.

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants