Skip to content

Commit cf0498a

Browse files
Simplify inline comments in parentheses handling logic
Reduced verbose comments to concise labels. Details are already covered by the function name is_non_commutative_or_comparison() and inline comments on Add/Mul operators. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7671ca4 commit cf0498a

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

src/generation/generate.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,9 +3082,7 @@ fn should_skip_paren_expr<'a>(node: &'a ParenExpr<'a>, context: &Context<'a>) ->
30823082
// Keep parens on left side of assignment if:
30833083
// - Contains type assertion: (obj.prop as Type) = value is valid, but obj.prop as Type = value is not
30843084
// - Ends with !: (x!) = y avoids ambiguity with !=
3085-
if assign_expr.left.range().contains(&node.range())
3086-
&& (is_type_assertion(node.expr.kind()) || expr_ends_with_non_null_assertion(&node.expr))
3087-
{
3085+
if assign_expr.left.range().contains(&node.range()) && (is_type_assertion(node.expr.kind()) || expr_ends_with_non_null_assertion(&node.expr)) {
30883086
return false;
30893087
}
30903088
}
@@ -3124,7 +3122,6 @@ fn should_skip_paren_expr<'a>(node: &'a ParenExpr<'a>, context: &Context<'a>) ->
31243122
}
31253123
}
31263124

3127-
31283125
// In non-PreferNone modes, we've handled all cases where parens should be removed
31293126
if context.config.use_parentheses != UseParentheses::PreferNone {
31303127
return false;
@@ -3218,21 +3215,16 @@ fn should_skip_paren_expr<'a>(node: &'a ParenExpr<'a>, context: &Context<'a>) ->
32183215
}
32193216

32203217
if parent_bin.right.range().contains(&node.range()) {
3221-
// Same operator - parens matter on right side for non-commutative ops
3222-
// Also for comparison/equality ops: a === b === c is (a === b) === c, different from a === (b === c)
3223-
// Addition: not associative due to type coercion: "x" + (4 + 2) = "x6" vs "x" + 4 + 2 = "x42"
3224-
// Multiplication: not associative due to floating-point precision
3218+
// RIGHT SIDE: Keep parens for left-associative operators
32253219
if is_non_commutative_or_comparison(&parent_bin.op()) {
32263220
return false;
32273221
}
32283222
} else {
3229-
// LEFT SIDE
3223+
// LEFT SIDE: Exponentiation is right-associative
32303224
if matches!(parent_bin.op(), BinaryOp::Exp) {
3231-
// Exponentiation is right-associative, so left side needs parens: (a ** b) ** c
32323225
return false;
32333226
}
3234-
// For left-associative operators, left side parens are redundant: (a + b) + c === a + b + c
3235-
// Allow removal by returning true (skip parens)
3227+
// LEFT SIDE: Remove redundant parens for left-associative operators
32363228
if is_non_commutative_or_comparison(&parent_bin.op()) {
32373229
return true;
32383230
}
@@ -3305,7 +3297,6 @@ fn should_skip_paren_expr<'a>(node: &'a ParenExpr<'a>, context: &Context<'a>) ->
33053297
}
33063298
}
33073299

3308-
// Keep parens for assignment expressions with member access, call, or new: (a = b).prop or (a = b)() or new (a = b)()
33093300
// Member access, call, and new have higher precedence than assignment, so parens are needed
33103301
if matches!(node.expr, Expr::Assign(_))
33113302
&& matches!(

0 commit comments

Comments
 (0)