Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore end-of-line comments when determining blank line rules #11342

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Loading