Skip to content

Commit

Permalink
Ignore blank lines between comments when counting newlines-after-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 22, 2023
1 parent 01843af commit 8894c95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 8894c95

Please sign in to comment.