Skip to content

Commit

Permalink
Correctly handle newlines after/before comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 6, 2023
1 parent ec33c3d commit b2ec055
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_python_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'fmt, 'ast, 'buf> JoinNodesBuilder<'fmt, 'ast, 'buf> {
};

match node_level {
NodeLevel::TopLevel => match dbg!(count_lines(last_end)) {
NodeLevel::TopLevel => match count_lines(last_end) {
0 | 1 => hard_line_break().fmt(self.fmt),
2 => empty_line().fmt(self.fmt),
_ => write!(self.fmt, [empty_line(), empty_line()]),
Expand Down
11 changes: 6 additions & 5 deletions crates/ruff_python_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,12 @@ Formatted twice:
#[ignore]
#[test]
fn quick_test() {
let src = r#"
while True:
if something.changed:
do.stuff() # trailing comment
other
let src = r#"AAAAAAAAAAAAA = AAAAAAAAAAAAA # type: ignore
call_to_some_function_asdf(
foo,
[AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
)
"#;
// Tokenize once
let mut tokens = Vec::new();
Expand Down

0 comments on commit b2ec055

Please sign in to comment.