Skip to content

Commit

Permalink
Fix formatting precedence of for loop parts.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbens-starkware committed Sep 9, 2024
1 parent 6679166 commit 582eda1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 1 addition & 3 deletions corelib/src/test/language_features/for_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ fn test_for_loop_array_variables() {
#[test]
fn test_for_loop_array_tuples() {
let mut i = 10;
for (
x, y
) in array![(10, 10), (11, 11), (12, 12)] {
for (x, y) in array![(10, 10), (11, 11), (12, 12)] {
assert_eq!(x, i);
assert_eq!(y, i);
i += 1;
Expand Down
23 changes: 23 additions & 0 deletions crates/cairo-lang-formatter/src/node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,29 @@ impl SyntaxNodeFormat for SyntaxNode {
| SyntaxKind::ExprUnary => Some(10),
_ => None,
},
Some(SyntaxKind::ExprFor) => match self.kind(db) {
SyntaxKind::ExprBlock => Some(1),
SyntaxKind::ExprBinary
| SyntaxKind::ExprErrorPropagate
| SyntaxKind::ExprFieldInitShorthand
| SyntaxKind::ExprFunctionCall
| SyntaxKind::ExprIf
| SyntaxKind::ExprList
| SyntaxKind::ExprMatch
| SyntaxKind::ExprMissing
| SyntaxKind::ExprParenthesized
| SyntaxKind::ExprPath
| SyntaxKind::ExprStructCtorCall
| SyntaxKind::ExprListParenthesized
| SyntaxKind::ArgListBraced
| SyntaxKind::ArgListBracketed
| SyntaxKind::ExprUnary => Some(2),
SyntaxKind::PatternEnum
| SyntaxKind::PatternTuple
| SyntaxKind::PatternStruct
| SyntaxKind::PatternFixedSizeArray => Some(3),
_ => None,
},
Some(SyntaxKind::StatementLet) => match self.kind(db) {
SyntaxKind::ExprBinary
| SyntaxKind::ExprBlock
Expand Down

0 comments on commit 582eda1

Please sign in to comment.