Skip to content

Commit

Permalink
fix: formatting for loop (#6807)
Browse files Browse the repository at this point in the history
## Description
Fix #6804

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.

Co-authored-by: IGI-111 <[email protected]>
  • Loading branch information
amiremohamadi and IGI-111 authored Jan 8, 2025
1 parent 40b3968 commit 96ee0b8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion swayfmt/src/utils/language/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl Format for Expr {
|formatter| -> Result<(), FormatterError> {
write!(formatted_code, "{} ", ForToken::AS_STR)?;
value_pattern.format(formatted_code, formatter)?;
write!(formatted_code, "{} ", InToken::AS_STR)?;
write!(formatted_code, " {} ", InToken::AS_STR)?;
iterator.format(formatted_code, formatter)?;
IfExpr::open_curly_brace(formatted_code, formatter)?;
block.get().format(formatted_code, formatter)?;
Expand Down
10 changes: 10 additions & 0 deletions swayfmt/src/utils/language/expr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ intermediate_whitespace
"{
let i = 42;
}");

fmt_test_expr!(basic_for_loop
"for iter in [0, 1, 7, 8, 15] {
let i = 42;
}",
intermediate_whitespace
"for iter in [0, 1, 7, 8, 15]{
let i = 42;
}"
);
40 changes: 40 additions & 0 deletions swayfmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3449,3 +3449,43 @@ fn tuple_field_access() {
"#},
);
}

#[test]
fn contract_for_loop() {
check(
indoc! {r#"
contract;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
let mut my_vec: Vec<u64> = Vec::new();
for iter in my_vec.iter() {
}
true
}
}
"#},
indoc! {r#"
contract;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
let mut my_vec: Vec<u64> = Vec::new();
for iter in my_vec.iter() { }
true
}
}
"#},
);
}

0 comments on commit 96ee0b8

Please sign in to comment.