From 582eda10d2bfd9dc586b7faebb4dd84da4b179e9 Mon Sep 17 00:00:00 2001 From: Gil Ben-Shachar Date: Mon, 9 Sep 2024 15:12:37 +0300 Subject: [PATCH] Fix formatting precedence of for loop parts. --- .../src/test/language_features/for_test.cairo | 4 +--- .../src/node_properties.rs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/corelib/src/test/language_features/for_test.cairo b/corelib/src/test/language_features/for_test.cairo index 6fa8feb31d8..67bf13b3537 100644 --- a/corelib/src/test/language_features/for_test.cairo +++ b/corelib/src/test/language_features/for_test.cairo @@ -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; diff --git a/crates/cairo-lang-formatter/src/node_properties.rs b/crates/cairo-lang-formatter/src/node_properties.rs index a69307bd586..f02ef223fa5 100644 --- a/crates/cairo-lang-formatter/src/node_properties.rs +++ b/crates/cairo-lang-formatter/src/node_properties.rs @@ -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