Skip to content

Commit 54c509e

Browse files
committed
fix(formatter): BestFitting doesn't exactly matches the conditinalGroup behavior in Prettier
1 parent 63c324d commit 54c509e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

crates/oxc_formatter/src/formatter/printer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,7 @@ impl<'a> Printer<'a> {
378378
} else {
379379
self.state.measured_group_fits = true;
380380

381-
let normal_variants = &best_fitting.variants()[..best_fitting.variants().len() - 1];
382-
383-
for variant in normal_variants {
381+
for variant in best_fitting.variants() {
384382
// Test if this variant fits and if so, use it. Otherwise try the next
385383
// variant.
386384

crates/oxc_formatter/src/utils/member_chain/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ impl<'a> Format<'a> for MemberChain<'a, '_> {
231231
}
232232
Ok(())
233233
});
234-
235-
let format_expanded = format_with(|f| write!(f, [self.head, indent(&group(&format_tail))]));
234+
let format_expanded = format_with(|f| write!(f, [self.head, indent(&format_tail)]));
236235

237236
let format_content = format_with(|f| {
238237
if has_comment || has_new_line_or_comment_between || self.groups_should_break(f) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const defaultColorDecoratorsEnablement = accessor
2+
.get(IConfigurationService)
3+
.getValue<'auto' | 'always' | 'never'>('longlonglonglonglonglonglonglonglong');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
const defaultColorDecoratorsEnablement = accessor
6+
.get(IConfigurationService)
7+
.getValue<'auto' | 'always' | 'never'>('longlonglonglonglonglonglonglonglong');
8+
9+
==================== Output ====================
10+
const defaultColorDecoratorsEnablement = accessor
11+
.get(IConfigurationService)
12+
.getValue<
13+
"auto" | "always" | "never"
14+
>("longlonglonglonglonglonglonglonglong");
15+
16+
===================== End =====================

0 commit comments

Comments
 (0)