Skip to content

Commit

Permalink
feat: remove curly braces with fmt (#4529)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves
https://github.com/noir-lang/noir/compare/master...Andy53:noir:fmt_remvoes_curly_braces_when_there_is_a_single_import?expand=1

Closes #4480 

## Summary\*
Removes curly braces from imports when there is only a single import.

`use dep::std::hash::{sha256};`
 
becomes:
`use dep::std::hash::sha256;


## Additional Context



## Documentation\*

Check one:
- [ X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [ X] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: jfecher <jfecher11@gmail.com>
  • Loading branch information
Andy53 and jfecher committed Mar 14, 2024
1 parent de4986e commit fe9a437
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion noir_stdlib/src/array.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cmp::{Ord};
use crate::cmp::Ord;

// TODO: Once we fully move to the new SSA pass this module can be removed and replaced
// by the methods in the `slice` module
Expand Down
9 changes: 8 additions & 1 deletion tooling/nargo_fmt/src/rewrite/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ impl UseTree {

let mut iter = self.path.iter().peekable();
while let Some(segment) = iter.next() {
let segment_str = segment.rewrite(visitor, shape);
let mut segment_str = segment.rewrite(visitor, shape);
if segment_str.contains('{')
&& !segment_str.contains(',')
&& !segment_str.contains("::")
{
let empty = "";
segment_str = segment_str.replace(['{', '}'], empty);
}
result.push_str(&segment_str);

if iter.peek().is_some() {
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_fmt/tests/expected/contract.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract Benchmarking {
context::Context, note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader},
log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet},
types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN},
types::address::{AztecAddress}
types::address::AztecAddress
};

struct Storage {
Expand Down
1 change: 1 addition & 0 deletions tooling/nargo_fmt/tests/expected/import_braces.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use dep::std::hash::sha256;
2 changes: 1 addition & 1 deletion tooling/nargo_fmt/tests/input/contract.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract Benchmarking {
context::Context, note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader},
log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet},
types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN},
types::address::{AztecAddress}
types::address::AztecAddress
};

struct Storage {
Expand Down
1 change: 1 addition & 0 deletions tooling/nargo_fmt/tests/input/import_braces.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use dep::std::hash::{sha256};

0 comments on commit fe9a437

Please sign in to comment.