Skip to content

Commit de8d6f8

Browse files
committed
chore(formatter): relax binary inlining rules
Signed-off-by: azjezz <[email protected]>
1 parent feb6445 commit de8d6f8

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

crates/formatter/src/internal/format/binaryish.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ pub(super) fn print_binaryish_expression<'arena>(
164164
let parts = print_binaryish_expression_parts(f, left, operator, right, is_inside_parenthesis, false);
165165

166166
if is_inside_parenthesis {
167+
let lhs_is_binary = left.is_binary();
168+
let rhs_is_binary = right.is_binary();
169+
if !lhs_is_binary && !rhs_is_binary {
170+
return Document::Group(Group::new(parts));
171+
}
172+
167173
return Document::Array(parts);
168174
}
169175

crates/formatter/tests/cases/issue_279/after.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
if (
44
in_array($object->getVeryLongAndInterestingObjectType(), SuperClass::VERY_LONG_AND_DESCRIPTIVE_CONSTANT_NAME) && (
5-
!$object->veryLongConditionCheckWithLotsOfText()
6-
&& !$object->evenLongerConditionCheckWithEvenMoreText()
5+
!$object->veryLongConditionCheckWithLotsOfText() && !$object->evenLongerConditionCheckWithEvenMoreText()
76
)
87
) {
98
}
@@ -25,8 +24,7 @@
2524
$object->getVeryLongAndInterestingObjectType(),
2625
SuperClass::VERY_LONG_AND_DESCRIPTIVE_CONSTANT_NAME,
2726
) && (
28-
!$object->veryLongConditionCheckWithLotsOfText()
29-
&& !$object->evenLongerConditionCheckWithEvenMoreText()
27+
!$object->veryLongConditionCheckWithLotsOfText() && !$object->evenLongerConditionCheckWithEvenMoreText()
3028
)
3129
) {
3230
}

crates/formatter/tests/cases/issue_796/after.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
$x &&
55
// Condition A
66
(
7-
$x
8-
&& $x ||
7+
$x && $x ||
98
// Condition B
10-
$x
11-
&& $x
9+
$x && $x
1210
)
1311
) {
1412
}

0 commit comments

Comments
 (0)