Skip to content

Commit c91e8c8

Browse files
authored
don't unwrap parenthesized assignments in calls (#816)
1 parent 0e63875 commit c91e8c8

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

fixtures/small/paren_expr_unwrap_actual.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@
3737

3838
# Ternary without keywords
3939
foo (condition ? a : b)
40+
41+
# Assignments we leave alone, for consistency with code like:
42+
#
43+
# if (var = thing)
44+
foo ((var = thing))
45+
foo(1, (var2 = thing))

fixtures/small/paren_expr_unwrap_expected.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@
3737

3838
# Ternary without keywords
3939
foo(condition ? a : b)
40+
41+
# Assignments we leave alone, for consistency with code like:
42+
#
43+
# if (var = thing)
44+
foo((var = thing))
45+
foo(1, (var2 = thing))

librubyfmt/src/format_prism.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4943,6 +4943,9 @@ fn is_keyword_expression(node: &prism::Node) -> bool {
49434943
Node::BeginNode { .. } => true,
49444944
// For completeness: other control flow that shouldn't be unwrapped
49454945
Node::ForNode { .. } => true,
4946+
// Assignments to local variables can be left wrapped for consistency with
4947+
// wrapping assignments in `if` conditions and the like.
4948+
Node::LocalVariableWriteNode { .. } => true,
49464949
_ => false,
49474950
}
49484951
}

0 commit comments

Comments
 (0)