Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: format global attributes #7401

Merged
merged 2 commits into from
Feb 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ contract Foo {

#[abi(bar)]
pub struct Bar {
inner: Field
inner: Field,
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
contract Foo {
pub struct T { x: [Field] }
pub struct T {
x: [Field],
}

impl T {
fn t(self) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
contract Foo {
pub struct PlaceholderStruct{x : u32 }
pub struct PlaceholderStruct {
x: u32,
}

#[contract_library_method]
pub fn has_mut(_context: &mut PlaceholderStruct) {}
Expand Down
2 changes: 1 addition & 1 deletion test_programs/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo "[workspace]" > Nargo.toml
echo "members = [" >> Nargo.toml

collect_dirs compile_success_empty
# collect_dirs compile_success_contract
collect_dirs compile_success_contract
collect_dirs compile_success_no_bug
collect_dirs compile_success_with_bug
collect_dirs execution_success
Expand Down
11 changes: 11 additions & 0 deletions tooling/nargo_fmt/src/formatter/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ impl<'a> Formatter<'a> {
let_statement: LetStatement,
visibility: ItemVisibility,
) {
self.format_secondary_attributes(let_statement.attributes.clone());

let group = self.chunk_formatter().format_global(let_statement, visibility);
self.write_indentation();
self.format_chunk_group(group);
Expand Down Expand Up @@ -99,4 +101,13 @@ mod tests {
let expected = "pub comptime mut global x: Field = 1;\n";
assert_format(src, expected);
}

#[test]
fn format_global_with_attributes() {
let src = " #[abi ( foo ) ] global x = 1 ; ";
let expected = "#[abi(foo)]
global x = 1;
";
assert_format(src, expected);
}
}
Loading