-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
ruff
] Needless else
clause (RUF047
)
Co-authored-by: Micha Reiser <micha@reiser.io>
- Loading branch information
1 parent
c0383da
commit b14a642
Showing
14 changed files
with
840 additions
and
7 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
crates/ruff_linter/resources/test/fixtures/ruff/RUF047_for.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
for _ in range(0): | ||
loop_body_is_not_checked() | ||
break | ||
else: | ||
pass | ||
|
||
|
||
for this in comment: | ||
belongs_to() # `for` | ||
else: | ||
... | ||
|
||
|
||
for this in second_comment: | ||
belongs() # to | ||
# `else` | ||
else: | ||
pass | ||
|
||
|
||
for _and in so: | ||
does() | ||
# this | ||
else: | ||
pass | ||
|
||
|
||
for of in course(): | ||
this() | ||
else: | ||
... # too | ||
|
||
|
||
for of in course(): | ||
this() | ||
else: | ||
... | ||
# too | ||
|
||
for of in course(): | ||
this() | ||
else: | ||
... | ||
# this comment does not belong to the else |
84 changes: 84 additions & 0 deletions
84
crates/ruff_linter/resources/test/fixtures/ruff/RUF047_if.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Errors | ||
|
||
if False: | ||
condition_is_not_evaluated() | ||
else: | ||
pass | ||
|
||
|
||
if this_comment(): | ||
belongs_to() # `if` | ||
else: | ||
... | ||
|
||
|
||
if elif_is(): | ||
treated() | ||
elif the_same(): | ||
as_if() | ||
else: | ||
pass | ||
|
||
|
||
if this_second_comment(): | ||
belongs() # to | ||
# `if` | ||
else: | ||
pass | ||
|
||
|
||
if of_course(): | ||
this() | ||
else: | ||
... | ||
# this comment doesn't belong to the if | ||
|
||
|
||
if of_course: this() | ||
else: ... | ||
|
||
|
||
if of_course: | ||
this() # comment | ||
else: ... | ||
|
||
|
||
def nested(): | ||
if a: | ||
b() | ||
else: | ||
... | ||
|
||
|
||
# No errors | ||
|
||
if this_second_comment(): | ||
belongs() # to | ||
# `else` | ||
else: | ||
pass | ||
|
||
|
||
if this_second_comment(): | ||
belongs() # to | ||
# `else` | ||
else: | ||
pass | ||
|
||
|
||
if of_course(): | ||
this() | ||
else: | ||
... # too | ||
|
||
|
||
if of_course(): | ||
this() | ||
else: | ||
... | ||
# comment | ||
|
||
|
||
if of_course: | ||
this() # comment | ||
else: ... # trailing |
71 changes: 71 additions & 0 deletions
71
crates/ruff_linter/resources/test/fixtures/ruff/RUF047_try.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
try: | ||
raise try_body_is_not_checked() | ||
except: | ||
pass | ||
else: | ||
pass | ||
|
||
|
||
try: | ||
this() | ||
except comment: | ||
belongs() | ||
except: | ||
to() # `except` | ||
else: | ||
... | ||
|
||
|
||
try: | ||
this() | ||
except (second, comment): | ||
belongs() # to | ||
# `else` | ||
else: | ||
pass | ||
|
||
|
||
try: | ||
and_so() | ||
except: | ||
does() | ||
# this | ||
else: | ||
... | ||
|
||
|
||
try: | ||
of_course() | ||
except: | ||
this() | ||
else: | ||
... # too | ||
|
||
try: | ||
of_course() | ||
except: | ||
this() | ||
else: | ||
... | ||
# This comment belongs to else | ||
finally: | ||
pass | ||
|
||
try: | ||
of_course() | ||
except: | ||
this() | ||
else: | ||
... | ||
# This comment belongs to finally | ||
finally: | ||
pass | ||
|
||
|
||
try: | ||
of_course() | ||
except: | ||
this() | ||
else: | ||
... | ||
# This comment belongs to the statement coming after the else |
44 changes: 44 additions & 0 deletions
44
crates/ruff_linter/resources/test/fixtures/ruff/RUF047_while.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
while True: | ||
loop_body_is_not_checked() | ||
break | ||
else: | ||
pass | ||
|
||
|
||
while this_comment: | ||
belongs_to() # `for` | ||
else: | ||
... | ||
|
||
|
||
while this_second_comment: | ||
belongs() # to | ||
# `else` | ||
else: | ||
pass | ||
|
||
|
||
while and_so: | ||
does() | ||
# this | ||
else: | ||
... | ||
|
||
|
||
while of_course(): | ||
this() | ||
else: | ||
... # too | ||
|
||
while of_course(): | ||
this() | ||
else: | ||
... | ||
# this comment belongs to the else | ||
|
||
while of_course(): | ||
this() | ||
else: | ||
... | ||
# this comment belongs to the statement coming after the else | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.