Skip to content

Commit 8e9ddee

Browse files
Ignore end-of-line comments when determining blank line rules (#11342)
## Summary Closes #11331.
1 parent 702d2fa commit 8e9ddee

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def b():
439439
# no error
440440
def test():
441441
pass
442-
442+
443443
# Wrongly indented comment
444444
pass
445445
# end
@@ -615,13 +615,13 @@ def g():
615615

616616
# E302
617617
class Test:
618-
618+
619619
pass
620-
620+
621621
def method1():
622622
return 1
623-
624-
623+
624+
625625
def method2():
626626
return 22
627627
# end
@@ -762,7 +762,7 @@ def b(self):
762762
def fn():
763763
pass
764764

765-
765+
766766
pass
767767
# end
768768

@@ -933,3 +933,13 @@ def a():
933933
async def b():
934934
pass
935935
# end
936+
937+
938+
# no error
939+
@overload
940+
def arrow_strip_whitespace(obj: Table, /, *cols: str) -> Table: ...
941+
@overload
942+
def arrow_strip_whitespace(obj: Array, /, *cols: str) -> Array: ... # type: ignore[misc]
943+
def arrow_strip_whitespace(obj, /, *cols):
944+
...
945+
# end

crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ struct LogicalLineInfo {
352352
kind: LogicalLineKind,
353353
first_token_range: TextRange,
354354

355-
// The token's kind right before the newline ending the logical line.
355+
// The kind of the last non-trivia token before the newline ending the logical line.
356356
last_token: TokenKind,
357357

358358
// The end of the logical line including the newline.
@@ -549,7 +549,9 @@ impl<'a> Iterator for LinePreprocessor<'a> {
549549
_ => {}
550550
}
551551

552-
last_token = token_kind;
552+
if !token_kind.is_trivia() {
553+
last_token = token_kind;
554+
}
553555
}
554556

555557
None

crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E303_E30.py.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ E30.py:625:2: E303 [*] Too many blank lines (2)
1313
Safe fix
1414
621 621 | def method1():
1515
622 622 | return 1
16-
623 623 |
17-
624 |-
16+
623 623 |
17+
624 |-
1818
625 624 | def method2():
1919
626 625 | return 22
2020
627 626 | # end
@@ -242,7 +242,7 @@ E30.py:766:5: E303 [*] Too many blank lines (2)
242242
762 762 | def fn():
243243
763 763 | pass
244244
764 764 |
245-
765 |-
245+
765 |-
246246
766 765 | pass
247247
767 766 | # end
248248
768 767 |

0 commit comments

Comments
 (0)