Skip to content
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
4 changes: 4 additions & 0 deletions tooling/nargo_fmt/src/formatter/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ impl Formatter<'_> {
}

pub(super) fn format_secondary_attributes(&mut self, attributes: Vec<SecondaryAttribute>) {
// Attributes and doc comments can be mixed, so between each attribute
// we format potential doc comments
for attribute in attributes {
self.format_outer_doc_comments();
self.format_secondary_attribute(attribute);
}
self.format_outer_doc_comments();
}

fn format_attribute(&mut self, attribute: Attribute) {
Expand Down
8 changes: 8 additions & 0 deletions tooling/nargo_fmt/src/formatter/doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
self.write_indentation();
let string = self.token.to_string();
let string = string.trim_end();
let string = string.replacen("///", "//", 1);

Check warning on line 63 in tooling/nargo_fmt/src/formatter/doc_comments.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (replacen)
self.write(&string);
self.bump();
self.write_line();
Expand All @@ -69,7 +69,7 @@
self.write_indentation();
let string = self.token.to_string();
let string = string.trim_end();
let string = string.replacen("/**", "/*", 1);

Check warning on line 72 in tooling/nargo_fmt/src/formatter/doc_comments.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (replacen)
self.write(&string);
self.bump();
self.write_line();
Expand Down Expand Up @@ -111,4 +111,12 @@
";
assert_format(src, expected);
}

#[test]
fn format_struct_outer_doc_comment_after_attribute() {
let src = "#[derive(Eq)]
/// A struct
struct Foo {}\n";
assert_format(src, src);
}
}
Loading