From a9b57638a4dd6a67dd40359eebb17f06c7ee186c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 4 Nov 2026 17:10:22 -0500 Subject: [PATCH] fix: don't hang indent the second operand of a multi-line comparison --- src/generation/generate.rs | 1 + .../BinaryExpression/BinaryExpression_All.txt | 76 +++++++++++++++++ tests/specs/issues/issue0747.txt | 84 +++++++++++++++++++ .../IfStatement_SpaceAround_True.txt | 2 +- 4 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 tests/specs/issues/issue0747.txt diff --git a/src/generation/generate.rs b/src/generation/generate.rs index faf872bf..78abbc7b 100644 --- a/src/generation/generate.rs +++ b/src/generation/generate.rs @@ -2601,6 +2601,7 @@ fn gen_binary_expr<'a>(node: &BinExpr<'a>, context: &mut Context<'a>) -> PrintIt && !node.op().is_logical() && !node.op().is_bit_logical() && !node.op().is_bit_shift() + && !node.op().is_equality() && node.op() != BinaryOp::Mod { false diff --git a/tests/specs/expressions/BinaryExpression/BinaryExpression_All.txt b/tests/specs/expressions/BinaryExpression/BinaryExpression_All.txt index 9911480a..19679598 100644 --- a/tests/specs/expressions/BinaryExpression/BinaryExpression_All.txt +++ b/tests/specs/expressions/BinaryExpression/BinaryExpression_All.txt @@ -249,6 +249,82 @@ if ( ) { } +== should format comparisons inline == +if ( + tttttttttttt == ttttttttttt +) { +} +if ( + tttttttttttt != ttttttttttt +) { +} +if ( + tttttttttttt === ttttttttttt +) { +} +if ( + tttttttttttt !== ttttttttttt +) { +} +if ( + tttttttttttt < ttttttttttt +) { +} +if ( + tttttttttttt <= ttttttttttt +) { +} +if ( + tttttttttttt > ttttttttttt +) { +} +if ( + tttttttttttt >= ttttttttttt +) { +} + +[expect] +if ( + tttttttttttt + == ttttttttttt +) { +} +if ( + tttttttttttt + != ttttttttttt +) { +} +if ( + tttttttttttt + === ttttttttttt +) { +} +if ( + tttttttttttt + !== ttttttttttt +) { +} +if ( + tttttttttttt + < ttttttttttt +) { +} +if ( + tttttttttttt + <= ttttttttttt +) { +} +if ( + tttttttttttt + > ttttttttttt +) { +} +if ( + tttttttttttt + >= ttttttttttt +) { +} + == should use a newline group for equality checks and not break them up so easily == let a = test == test; let b = test === test; diff --git a/tests/specs/issues/issue0747.txt b/tests/specs/issues/issue0747.txt new file mode 100644 index 00000000..2cb075f5 --- /dev/null +++ b/tests/specs/issues/issue0747.txt @@ -0,0 +1,84 @@ +~~ lineWidth: 80, indentWidth: 4, binaryExpression.operatorPosition: sameLine ~~ +== should not indent the second operand of a comparison in parens == +function mousePanExceedsStickyThreshold(): boolean { + return ( + Math.abs(panAccumulatedDelta.value) > + panAccumulatedDeltaThreshold.value + ); +} + +[expect] +function mousePanExceedsStickyThreshold(): boolean { + return ( + Math.abs(panAccumulatedDelta.value) > + panAccumulatedDeltaThreshold.value + ); +} + +== should indent comparisons the same as other binary expressions == +function mousePanExceedsStickyThreshold(): boolean { + return ( + Math.abs(panAccumulatedDelta.value) === + panAccumulatedDeltaThreshold.value + ); +} + +function mousePanExceedsStickyThreshold(): boolean { + return ( + Math.abs(panAccumulatedDelta.value) + + panAccumulatedDeltaThreshold.value + ); +} + +const isOver = () => + Math.abs(panAccumulatedDelta.value) <= + panAccumulatedDeltaThreshold.value; + +const values = [ + Math.abs(panAccumulatedDelta.value) != + panAccumulatedDeltaThreshold.value, +]; + +call( + Math.abs(panAccumulatedDelta.value) >= + panAccumulatedDeltaThreshold.value, +); + +call( + Math.abs(panAccumulatedDelta.value) + + panAccumulatedDeltaThreshold.value, +); + +[expect] +function mousePanExceedsStickyThreshold(): boolean { + return ( + Math.abs(panAccumulatedDelta.value) === + panAccumulatedDeltaThreshold.value + ); +} + +function mousePanExceedsStickyThreshold(): boolean { + return ( + Math.abs(panAccumulatedDelta.value) + + panAccumulatedDeltaThreshold.value + ); +} + +const isOver = () => + Math.abs(panAccumulatedDelta.value) <= + panAccumulatedDeltaThreshold.value; + +const values = [ + Math.abs(panAccumulatedDelta.value) != + panAccumulatedDeltaThreshold.value, +]; + +call( + Math.abs(panAccumulatedDelta.value) >= + panAccumulatedDeltaThreshold.value, +); + +call( + Math.abs(panAccumulatedDelta.value) + + panAccumulatedDeltaThreshold.value, +); diff --git a/tests/specs/statements/ifStatement/IfStatement_SpaceAround_True.txt b/tests/specs/statements/ifStatement/IfStatement_SpaceAround_True.txt index 9541e4f8..9d05dd3a 100644 --- a/tests/specs/statements/ifStatement/IfStatement_SpaceAround_True.txt +++ b/tests/specs/statements/ifStatement/IfStatement_SpaceAround_True.txt @@ -14,6 +14,6 @@ if (somereallylongidentifier <= anotherreallylongidentifier) { [expect] if ( somereallylongidentifier - <= anotherreallylongidentifier + <= anotherreallylongidentifier ) { }