Skip to content

Commit

Permalink
Do not print parens for parameterless attributes in swayfmt (FuelLabs…
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Nov 29, 2022
1 parent 52bcfc7 commit e3df97d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
22 changes: 22 additions & 0 deletions swayfmt/src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,28 @@ fn func_with_multiline_collections() {
fn func_with_multiline_collections() {
let x = ("hello", "world");
}
"#;
let mut formatter = Formatter::default();
let formatted_sway_code =
Formatter::format(&mut formatter, Arc::from(sway_code_to_format), None).unwrap();
assert_eq!(correct_sway_code, formatted_sway_code);
assert!(test_stability(formatted_sway_code, formatter));
}
#[test]
fn test_parameterless_attributes() {
let sway_code_to_format = r#"library my_lib;
abi MyContract {
#[test]
fn foo();
}
"#;
let correct_sway_code = r#"library my_lib;
abi MyContract {
#[test]
fn foo();
}
"#;
let mut formatter = Formatter::default();
let formatted_sway_code =
Expand Down
12 changes: 6 additions & 6 deletions swayfmt/src/utils/language/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ impl Format for AttributeDecl {
Self::open_square_bracket(formatted_code, formatter)?;
// name e.g. `storage`
write!(formatted_code, "{}", attr.name.span().as_str())?;
// `(`
Self::open_parenthesis(formatted_code, formatter)?;
// format and add args e.g. `read, write`
if let Some(args) = &attr.args {
// `(`
Self::open_parenthesis(formatted_code, formatter)?;
// format and add args e.g. `read, write`
args.get().format(formatted_code, formatter)?;
}
// ')'
Self::close_parenthesis(formatted_code, formatter)?;
// ')'
Self::close_parenthesis(formatted_code, formatter)?;
};
// `]\n`
Self::close_square_bracket(formatted_code, formatter)?;

Expand Down

0 comments on commit e3df97d

Please sign in to comment.