-
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.
[
pylint
] Better diagnostic range (PLR1702
)
- Loading branch information
1 parent
b8e5b95
commit e6bd295
Showing
5 changed files
with
114 additions
and
25 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
crates/ruff_linter/resources/test/fixtures/pylint/too_many_nested_blocks_2.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,33 @@ | ||
def foo(): | ||
while a: # \ | ||
if b: # | | ||
for c in range(3): # | These should not be reported, | ||
if d: # | as they don't exceed the max depth. | ||
while e: # | | ||
if f: # / | ||
|
||
for g in z: # This statement is the first to exceed the limit. | ||
print(p) # Thus, it is reported but not any of its substatements. | ||
pass # | ||
|
||
with y: # The former statement was already reported. | ||
print(x) # Thus, reporting these is redundant. | ||
print(u) # | ||
|
||
else: # Other blocks of an ancestor statement | ||
print(q) # are also not reported. | ||
|
||
|
||
def foo(): | ||
while a: # \ | ||
if b: # | | ||
for c in range(3): # | These should not be reported, | ||
if d: # | as they don't exceed the max depth. | ||
while e: # | | ||
if f: # / | ||
|
||
if x == y: # This statement is the first to exceed the limit. | ||
print(p) # It is therefore reported. | ||
|
||
elif y > x: # This block belongs to the same statement, | ||
print(p) # and so it is not reported on its own. |
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
19 changes: 7 additions & 12 deletions
19
...ylint/snapshots/ruff_linter__rules__pylint__tests__PLR1702_too_many_nested_blocks.py.snap
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 |
---|---|---|
@@ -1,17 +1,12 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pylint/mod.rs | ||
--- | ||
too_many_nested_blocks.py:2:5: PLR1702 Too many nested blocks (6 > 5) | ||
too_many_nested_blocks.py:8:1: PLR1702 Too many nested blocks (6 > 5) | ||
| | ||
1 | def correct_fruits(fruits) -> bool: | ||
2 | / if len(fruits) > 1: # PLR1702 | ||
3 | | if "apple" in fruits: | ||
4 | | if "orange" in fruits: | ||
5 | | count = fruits["orange"] | ||
6 | | if count % 2: | ||
7 | | if "kiwi" in fruits: | ||
8 | | if count == 2: | ||
9 | | return True | ||
| |_______________________________________^ PLR1702 | ||
10 | return False | ||
6 | if count % 2: | ||
7 | if "kiwi" in fruits: | ||
8 | if count == 2: | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ PLR1702 | ||
9 | return True | ||
10 | return False | ||
| |
21 changes: 21 additions & 0 deletions
21
...int/snapshots/ruff_linter__rules__pylint__tests__PLR1702_too_many_nested_blocks_2.py.snap
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,21 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pylint/mod.rs | ||
--- | ||
too_many_nested_blocks_2.py:9:1: PLR1702 Too many nested blocks (7 > 5) | ||
| | ||
7 | if f: # / | ||
8 | | ||
9 | for g in z: # This statement is the first to exceed the limit. | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1702 | ||
10 | print(p) # Thus, it is reported but not any of its substatements. | ||
11 | pass # | ||
| | ||
|
||
too_many_nested_blocks_2.py:29:1: PLR1702 Too many nested blocks (7 > 5) | ||
| | ||
27 | if f: # / | ||
28 | | ||
29 | if x == y: # This statement is the first to exceed the limit. | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1702 | ||
30 | print(p) # It is therefore reported. | ||
| |