Skip to content

Commit

Permalink
fix(nargo_fmt): let doc comment could come after regular comment
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jan 13, 2025
1 parent a9acf5a commit 1abb5f8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tooling/nargo_fmt/src/formatter/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ impl<'a, 'b> ChunkFormatter<'a, 'b> {

// Now write any leading comment respecting multiple newlines after them
group.leading_comment(self.chunk(|formatter| {
// Doc comments for a let statement could come before a potential non-doc comment
if formatter.token.kind() == TokenKind::OuterDocComment {
formatter.format_outer_doc_comments();
}

formatter.skip_comments_and_whitespace_writing_multiple_lines_if_found();

// Or doc comments could come after a potential non-doc comment
if formatter.token.kind() == TokenKind::OuterDocComment {
formatter.format_outer_doc_comments();
}
}));

ignore_next |= self.ignore_next;
Expand Down Expand Up @@ -390,6 +397,21 @@ mod tests {
assert_format(src, expected);
}

#[test]
fn format_let_statement_with_unsafe_and_comment_before_it() {
let src = " fn foo() {
// Some comment
/// Safety: some doc
let x = unsafe { 1 } ; } ";
let expected = "fn foo() {
// Some comment
/// Safety: some doc
let x = unsafe { 1 };
}
";
assert_format(src, expected);
}

#[test]
fn format_assign() {
let src = " fn foo() { x = 2 ; } ";
Expand Down

0 comments on commit 1abb5f8

Please sign in to comment.