Skip to content

fix: don't hang indent the second operand of a multi-line comparison - #884

Merged
dsherret merged 1 commit into
mainfrom
fix-comparison-binary-indent
Nov 4, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix-comparison-binary-indent

Conversation

@dsherret

@dsherret dsherret commented Nov 4, 2026

Copy link
Copy Markdown
Member

Closes #747

A multi-line comparison got a hanging indent on its second operand in places where other binary expressions like + and && stay at the first operand's level (indentWidth: 4, binaryExpression.operatorPosition: sameLine):

function mousePanExceedsStickyThreshold(): boolean {
    return (
        Math.abs(panAccumulatedDelta.value) >
            panAccumulatedDeltaThreshold.value
    );
}

Comparison operators (==, !=, ===, !==, <, <=, >, >=) are now treated like the other operators that don't indent there (ex. return and if parens, arrow function bodies, and array elements):

function mousePanExceedsStickyThreshold(): boolean {
    return (
        Math.abs(panAccumulatedDelta.value) >
        panAccumulatedDeltaThreshold.value
    );
}

Call arguments, expression statements, assignments and comparisons nested in another binary expression still indent the same way + does.

This changes default output. In the regression corpus I use, it changed 127 files (mostly broken if ( conditions) and the output is stable.

Tests

  • issue0747.txt has the issue's example, plus comparisons in return parens, arrow function bodies, array elements and call arguments.
  • BinaryExpression_All.txt has a "should format comparisons inline" case with all eight operators, like the existing bitwise, bitshift and mod cases.
  • The multi-line case in IfStatement_SpaceAround_True.txt no longer indents its <= line.

@dsherret
dsherret merged commit 3c05101 into main Nov 4, 2026
1 check passed
@dsherret
dsherret deleted the fix-comparison-binary-indent branch November 4, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant