From b7ace682af1ab8a43308457302f08b151af342db Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Fri, 14 Feb 2025 18:01:57 -0300 Subject: [PATCH] fix: format global attributes (#7401) --- .../abi_attribute/src/main.nr | 2 +- .../contract_with_impl/src/main.nr | 4 +++- .../non_entry_point_method/src/main.nr | 4 +++- test_programs/format.sh | 2 +- tooling/nargo_fmt/src/formatter/global.rs | 11 +++++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/test_programs/compile_success_contract/abi_attribute/src/main.nr b/test_programs/compile_success_contract/abi_attribute/src/main.nr index c4d4a24e3c2..5091852d581 100644 --- a/test_programs/compile_success_contract/abi_attribute/src/main.nr +++ b/test_programs/compile_success_contract/abi_attribute/src/main.nr @@ -4,6 +4,6 @@ contract Foo { #[abi(bar)] pub struct Bar { - inner: Field + inner: Field, } } diff --git a/test_programs/compile_success_contract/contract_with_impl/src/main.nr b/test_programs/compile_success_contract/contract_with_impl/src/main.nr index 9d45b88fbc9..f583f888a00 100644 --- a/test_programs/compile_success_contract/contract_with_impl/src/main.nr +++ b/test_programs/compile_success_contract/contract_with_impl/src/main.nr @@ -1,5 +1,7 @@ contract Foo { - pub struct T { x: [Field] } + pub struct T { + x: [Field], + } impl T { fn t(self) { diff --git a/test_programs/compile_success_contract/non_entry_point_method/src/main.nr b/test_programs/compile_success_contract/non_entry_point_method/src/main.nr index f49c2f14f9d..3487ff2b94e 100644 --- a/test_programs/compile_success_contract/non_entry_point_method/src/main.nr +++ b/test_programs/compile_success_contract/non_entry_point_method/src/main.nr @@ -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) {} diff --git a/test_programs/format.sh b/test_programs/format.sh index 4f6f3e21916..8fa96541f92 100755 --- a/test_programs/format.sh +++ b/test_programs/format.sh @@ -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 diff --git a/tooling/nargo_fmt/src/formatter/global.rs b/tooling/nargo_fmt/src/formatter/global.rs index 783629c8e32..c351e15e3b6 100644 --- a/tooling/nargo_fmt/src/formatter/global.rs +++ b/tooling/nargo_fmt/src/formatter/global.rs @@ -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); @@ -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); + } }