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

[ruff] Empty branches (RUF050) #14763

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF050_for.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
###
# E = Empty
# N = Not empty
# O = Omitted
###


# Unsafe fix: Remove statement
for E in O:
...


# Unsafe fix: Remove statement
for E in E:
pass
else:
...


# No fix
for E in N:
pass
else:
print()


# No error
for N in O:
print()


# Safe fix: Remove `else` branch
for N in E:
print()
else:
...


# No error
for N in N:
print()
else:
print()
175 changes: 175 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF050_if.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
###
# E = Empty
# N = Not empty
# O = Omitted
###


# Unsafe fix: Remove statement
if EOO:
pass


# Unsafe fix: Remove statement
if EOE:
...
else:
pass


# No fix
if EON:
...
else:
print()


# Unsafe fix: Remove statement
if EEO:
pass
elif _:
...


# Unsafe fix: Remove statement
if EEE:
pass
elif _:
...
else:
pass


# No fix
# Display-only fix: Remove `elif` branch
if EEN:
pass
elif _:
...
else:
print()


# No fix
if ENO:
pass
elif _:
print()


# No fix
# Safe fix: Remove `else` branch
if ENE:
...
elif _:
print()
else:
pass


# No fix
if ENN:
...
elif _:
print()
else:
print()


# No error
if NOO:
print()


# Safe fix: Remove `else` branch
if NOE:
print()
else:
pass


# No error
if NON:
print()
else:
print()


# Unsafe fix: Remove `elif` branch
if NEO:
print()
elif _:
...


# Display-only fix: Remove `elif` branch
# Safe fix: Remove `else` branch
if NEE:
print()
elif _:
pass
else:
...


# Display-only fix: Remove `elif` branch
if NEN:
print()
elif _:
pass
else:
print()


# No error
if NNO:
print()
elif _:
print()


# Safe fix: Remove `else` branch
if NNE:
print()
elif _:
print()
else:
...


# No error
if NNN:
print()
elif _:
print()
else:
print()


#####


# Display-only fix: Remove `elif` branch
# Unsafe fix: Remove `elif` branch
if NEE_:
print()
elif _:
pass
elif _:
...


# Unsafe fix: Remove `elif` branch
if NEO_:
print()
# Lorem ipsum
elif _:
...


# Unsafe fix: Remove `else` branch
if NOE_:
print()
else:
# Lorem ipsum
pass
Loading
Loading