-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
pycodestyle
] Do not ignore lines before the first logical line in …
…blank lines rules (#10382) ## Summary Ignoring all lines until the first logical line does not match the behavior from pycodestyle. This PR therefore removes the `if state.is_not_first_logical_line` skipping the line check before the first logical line, and applies it only to `E302`. For example, in the snippet below a rule violation should be detected on the second comment and on the import. ```python # first comment # second comment import foo ``` Fixes #10374 ## Test Plan Add test cases, update the snapshots and verify the ecosystem check output
- Loading branch information
1 parent
5f40371
commit e944c16
Showing
18 changed files
with
211 additions
and
3 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
crates/ruff_linter/resources/test/fixtures/pycodestyle/E302_first_line_docstring.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,4 @@ | ||
"""Test where the error is after the module's docstring.""" | ||
|
||
def fn(): | ||
pass |
4 changes: 4 additions & 0 deletions
4
crates/ruff_linter/resources/test/fixtures/pycodestyle/E302_first_line_expression.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,4 @@ | ||
"Test where the first line is a comment, " + "and the rule violation follows it." | ||
|
||
def fn(): | ||
pass |
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/pycodestyle/E302_first_line_function.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,5 @@ | ||
def fn1(): | ||
pass | ||
|
||
def fn2(): | ||
pass |
4 changes: 4 additions & 0 deletions
4
crates/ruff_linter/resources/test/fixtures/pycodestyle/E302_first_line_statement.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,4 @@ | ||
print("Test where the first line is a statement, and the rule violation follows it.") | ||
|
||
def fn(): | ||
pass |
6 changes: 6 additions & 0 deletions
6
crates/ruff_linter/resources/test/fixtures/pycodestyle/E303_first_line_comment.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,6 @@ | ||
# Test where the first line is a comment, and the rule violation follows it. | ||
|
||
|
||
|
||
def fn(): | ||
pass |
6 changes: 6 additions & 0 deletions
6
crates/ruff_linter/resources/test/fixtures/pycodestyle/E303_first_line_docstring.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,6 @@ | ||
"""Test where the error is after the module's docstring.""" | ||
|
||
|
||
|
||
def fn(): | ||
pass |
6 changes: 6 additions & 0 deletions
6
crates/ruff_linter/resources/test/fixtures/pycodestyle/E303_first_line_expression.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,6 @@ | ||
"Test where the first line is a comment, " + "and the rule violation follows it." | ||
|
||
|
||
|
||
def fn(): | ||
pass |
6 changes: 6 additions & 0 deletions
6
crates/ruff_linter/resources/test/fixtures/pycodestyle/E303_first_line_statement.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,6 @@ | ||
print("Test where the first line is a statement, and the rule violation follows it.") | ||
|
||
|
||
|
||
def fn(): | ||
pass |
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: 19 additions & 0 deletions
19
.../snapshots/ruff_linter__rules__pycodestyle__tests__E302_E302_first_line_docstring.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,19 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E302_first_line_docstring.py:3:1: E302 [*] Expected 2 blank lines, found 1 | ||
| | ||
1 | """Test where the error is after the module's docstring.""" | ||
2 | | ||
3 | def fn(): | ||
| ^^^ E302 | ||
4 | pass | ||
| | ||
= help: Add missing blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | """Test where the error is after the module's docstring.""" | ||
2 2 | | ||
3 |+ | ||
3 4 | def fn(): | ||
4 5 | pass |
19 changes: 19 additions & 0 deletions
19
...snapshots/ruff_linter__rules__pycodestyle__tests__E302_E302_first_line_expression.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,19 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E302_first_line_expression.py:3:1: E302 [*] Expected 2 blank lines, found 1 | ||
| | ||
1 | "Test where the first line is a comment, " + "and the rule violation follows it." | ||
2 | | ||
3 | def fn(): | ||
| ^^^ E302 | ||
4 | pass | ||
| | ||
= help: Add missing blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | "Test where the first line is a comment, " + "and the rule violation follows it." | ||
2 2 | | ||
3 |+ | ||
3 4 | def fn(): | ||
4 5 | pass |
20 changes: 20 additions & 0 deletions
20
...e/snapshots/ruff_linter__rules__pycodestyle__tests__E302_E302_first_line_function.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,20 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E302_first_line_function.py:4:1: E302 [*] Expected 2 blank lines, found 1 | ||
| | ||
2 | pass | ||
3 | | ||
4 | def fn2(): | ||
| ^^^ E302 | ||
5 | pass | ||
| | ||
= help: Add missing blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | def fn1(): | ||
2 2 | pass | ||
3 3 | | ||
4 |+ | ||
4 5 | def fn2(): | ||
5 6 | pass |
19 changes: 19 additions & 0 deletions
19
.../snapshots/ruff_linter__rules__pycodestyle__tests__E302_E302_first_line_statement.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,19 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E302_first_line_statement.py:3:1: E302 [*] Expected 2 blank lines, found 1 | ||
| | ||
1 | print("Test where the first line is a statement, and the rule violation follows it.") | ||
2 | | ||
3 | def fn(): | ||
| ^^^ E302 | ||
4 | pass | ||
| | ||
= help: Add missing blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | print("Test where the first line is a statement, and the rule violation follows it.") | ||
2 2 | | ||
3 |+ | ||
3 4 | def fn(): | ||
4 5 | pass |
18 changes: 18 additions & 0 deletions
18
...le/snapshots/ruff_linter__rules__pycodestyle__tests__E303_E303_first_line_comment.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,18 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E303_first_line_comment.py:5:1: E303 [*] Too many blank lines (3) | ||
| | ||
5 | def fn(): | ||
| ^^^ E303 | ||
6 | pass | ||
| | ||
= help: Remove extraneous blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | # Test where the first line is a comment, and the rule violation follows it. | ||
2 2 | | ||
3 3 | | ||
4 |- | ||
5 4 | def fn(): | ||
6 5 | pass |
18 changes: 18 additions & 0 deletions
18
.../snapshots/ruff_linter__rules__pycodestyle__tests__E303_E303_first_line_docstring.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,18 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E303_first_line_docstring.py:5:1: E303 [*] Too many blank lines (3) | ||
| | ||
5 | def fn(): | ||
| ^^^ E303 | ||
6 | pass | ||
| | ||
= help: Remove extraneous blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | """Test where the error is after the module's docstring.""" | ||
2 2 | | ||
3 3 | | ||
4 |- | ||
5 4 | def fn(): | ||
6 5 | pass |
18 changes: 18 additions & 0 deletions
18
...snapshots/ruff_linter__rules__pycodestyle__tests__E303_E303_first_line_expression.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,18 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E303_first_line_expression.py:5:1: E303 [*] Too many blank lines (3) | ||
| | ||
5 | def fn(): | ||
| ^^^ E303 | ||
6 | pass | ||
| | ||
= help: Remove extraneous blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | "Test where the first line is a comment, " + "and the rule violation follows it." | ||
2 2 | | ||
3 3 | | ||
4 |- | ||
5 4 | def fn(): | ||
6 5 | pass |
18 changes: 18 additions & 0 deletions
18
.../snapshots/ruff_linter__rules__pycodestyle__tests__E303_E303_first_line_statement.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,18 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E303_first_line_statement.py:5:1: E303 [*] Too many blank lines (3) | ||
| | ||
5 | def fn(): | ||
| ^^^ E303 | ||
6 | pass | ||
| | ||
= help: Remove extraneous blank line(s) | ||
|
||
ℹ Safe fix | ||
1 1 | print("Test where the first line is a statement, and the rule violation follows it.") | ||
2 2 | | ||
3 3 | | ||
4 |- | ||
5 4 | def fn(): | ||
6 5 | pass |