Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/generation/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions tests/specs/expressions/BinaryExpression/BinaryExpression_All.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
84 changes: 84 additions & 0 deletions tests/specs/issues/issue0747.txt
Original file line number Diff line number Diff line change
@@ -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,
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ if (somereallylongidentifier <= anotherreallylongidentifier) {
[expect]
if (
somereallylongidentifier
<= anotherreallylongidentifier
<= anotherreallylongidentifier
) {
}
Loading