Skip to content

Commit

Permalink
Ignore end-of-line comments when determining blank line rules (#11342)
Browse files Browse the repository at this point in the history
## Summary

Closes #11331.
  • Loading branch information
charliermarsh committed May 8, 2024
1 parent 702d2fa commit 8e9ddee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
22 changes: 16 additions & 6 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E30.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def b():
# no error
def test():
pass

# Wrongly indented comment
pass
# end
Expand Down Expand Up @@ -615,13 +615,13 @@ def g():

# E302
class Test:

pass

def method1():
return 1


def method2():
return 22
# end
Expand Down Expand Up @@ -762,7 +762,7 @@ def b(self):
def fn():
pass


pass
# end

Expand Down Expand Up @@ -933,3 +933,13 @@ def a():
async def b():
pass
# end


# no error
@overload
def arrow_strip_whitespace(obj: Table, /, *cols: str) -> Table: ...
@overload
def arrow_strip_whitespace(obj: Array, /, *cols: str) -> Array: ... # type: ignore[misc]
def arrow_strip_whitespace(obj, /, *cols):
...
# end
6 changes: 4 additions & 2 deletions crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ struct LogicalLineInfo {
kind: LogicalLineKind,
first_token_range: TextRange,

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

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

last_token = token_kind;
if !token_kind.is_trivia() {
last_token = token_kind;
}
}

None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ E30.py:625:2: E303 [*] Too many blank lines (2)
Safe fix
621 621 | def method1():
622 622 | return 1
623 623 |
624 |-
623 623 |
624 |-
625 624 | def method2():
626 625 | return 22
627 626 | # end
Expand Down Expand Up @@ -242,7 +242,7 @@ E30.py:766:5: E303 [*] Too many blank lines (2)
762 762 | def fn():
763 763 | pass
764 764 |
765 |-
765 |-
766 765 | pass
767 766 | # end
768 767 |

0 comments on commit 8e9ddee

Please sign in to comment.