Skip to content

Commit cdfa53c

Browse files
committed
fix(formatter): correct indentation for flattened binary chains with trailing comments
closes #634 Signed-off-by: azjezz <[email protected]>
1 parent 331e3b0 commit cdfa53c

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ pub(super) fn print_binaryish_expression<'arena>(
171171
return Document::Group(Group::new(parts));
172172
}
173173

174-
let first_group_index = parts.iter().position(|part| matches!(part, Document::Group(_)));
175-
176-
let split_index = first_group_index.unwrap_or(0);
174+
let split_index = 1.min(parts.len());
177175
let mut head_parts = parts;
178176
let tail_parts = head_parts.split_off(split_index);
179177

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
function x(): iterable
4+
{
5+
yield 'INSERT IGNORE INTO `table1` (`col1`, `col2`, `col3`)'
6+
. ' SELECT `col1`, `col2`, `col3` FROM table2' // comment 1
7+
. ' WHERE `col4` = "val1"'; // comment 2
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
function x(): iterable
4+
{
5+
yield 'INSERT IGNORE INTO `table1` (`col1`, `col2`, `col3`)'
6+
. ' SELECT `col1`, `col2`, `col3` FROM table2' // comment 1
7+
. ' WHERE `col4` = "val1"'; // comment 2
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FormatSettings::default()

crates/formatter/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ test_case!(issue_536);
240240
test_case!(issue_556);
241241
test_case!(issue_602);
242242
test_case!(issue_683);
243+
test_case!(issue_634);
243244

244245
#[test]
245246
fn test_all_test_cases_are_ran() {

0 commit comments

Comments
 (0)