Skip to content

Commit

Permalink
fix: preserve newlines between comments when formatting statements (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Nov 22, 2024
1 parent 0a6207d commit d94eb08
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tooling/nargo_fmt/src/formatter/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ impl<'a, 'b> ChunkFormatter<'a, 'b> {

// Finally format the comment, if any
group.text(self.chunk(|formatter| {
formatter.skip_comments_and_whitespace();
formatter.skip_comments_and_whitespace_writing_multiple_lines_if_found();
}));

group.decrease_indentation();
Expand Down
30 changes: 30 additions & 0 deletions tooling/nargo_fmt/src/formatter/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,36 @@ fn baz() { let z = 3 ;
let y = 2;
}
";
let expected = src;
assert_format(src, expected);
}

#[test]
fn keeps_newlines_between_comments_no_statements() {
let src = "fn foo() {
// foo
// bar
// baz
}
";
let expected = src;
assert_format(src, expected);
}

#[test]
fn keeps_newlines_between_comments_one_statement() {
let src = "fn foo() {
let x = 1;
// foo
// bar
// baz
}
";
let expected = src;
assert_format(src, expected);
Expand Down

0 comments on commit d94eb08

Please sign in to comment.