@@ -554,7 +554,7 @@ impl ArrayExpression {
554
554
fn recast ( & self , buf : & mut String , options : & FormatOptions , indentation_level : usize , ctxt : ExprContext ) {
555
555
let num_items = self . elements . len ( ) + self . non_code_meta . non_code_nodes_len ( ) ;
556
556
let mut elems = self . elements . iter ( ) ;
557
- let mut items_buf = String :: with_capacity ( 512 ) ;
557
+ let mut items_buf = String :: with_capacity ( 256 ) ;
558
558
let mut item_spans = Vec :: with_capacity ( num_items) ;
559
559
let mut found_line_comment = false ;
560
560
@@ -568,17 +568,19 @@ impl ArrayExpression {
568
568
} else {
569
569
let el = elems. next ( ) . unwrap ( ) ;
570
570
el. recast ( & mut items_buf, options, 0 , ExprContext :: Other ) ;
571
- items_buf. push_str ( ", " ) ;
571
+ if i < num_items - 1 {
572
+ items_buf. push_str ( ", " ) ;
573
+ }
572
574
}
573
575
let end = items_buf. len ( ) ;
574
576
item_spans. push ( ( start, end) ) ;
575
577
}
576
578
579
+ let flat_length = items_buf. len ( ) + 2 ; // +2 is for the [ and ] which will surround the items.
577
580
let max_array_length = 40 ;
578
- let flat_length = items_buf. trim_end_matches ( ", " ) . len ( ) ;
579
- let use_flat = flat_length <= max_array_length && !found_line_comment;
581
+ let multi_line = flat_length > max_array_length || found_line_comment;
580
582
581
- if use_flat {
583
+ if !multi_line {
582
584
buf. push ( '[' ) ;
583
585
buf. push_str ( & items_buf[ ..flat_length] ) ;
584
586
buf. push ( ']' ) ;
@@ -2991,7 +2993,7 @@ fn function001() {
2991
2993
fn check_arr ( ) {
2992
2994
let code = "[
2993
2995
-0.8111463382182231,
2994
- -0.41814807547140576,
2996
+ -0.41814807547140576
2995
2997
]
2996
2998
" ;
2997
2999
0 commit comments