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 blank lines between comments when counting newlines-after-imports #7607

Merged
merged 1 commit into from
Sep 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ def func():


x = 1

# Regression test for: https://github.com/astral-sh/ruff/issues/7604
import os

# Defaults for arguments are defined here
# args.threshold = None;


logger = logging.getLogger("FastProject")
7 changes: 6 additions & 1 deletion crates/ruff_python_formatter/src/statement/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
// a leading comment.
match self.kind {
SuiteKind::TopLevel => {
match lines_after_ignoring_trivia(preceding.end(), source) {
let end = if let Some(last_trailing) = preceding_comments.trailing.last() {
last_trailing.end()
} else {
preceding.end()
};
match lines_after(end, source) {
0..=2 => empty_line().fmt(f)?,
_ => match source_type {
PySourceType::Stub => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def func():


x = 1

# Regression test for: https://github.com/astral-sh/ruff/issues/7604
import os

# Defaults for arguments are defined here
# args.threshold = None;


logger = logging.getLogger("FastProject")
```

## Output
Expand Down Expand Up @@ -130,6 +139,16 @@ def func():
import sys

x = 1


# Regression test for: https://github.com/astral-sh/ruff/issues/7604
import os

# Defaults for arguments are defined here
# args.threshold = None;


logger = logging.getLogger("FastProject")
```


Expand Down
Loading