feat(rome_formatter): implement fill-printing for array expressions
MODIFY
crates/rome_formatter/src/format_element.rs
crates/rome_formatter/src/format_element.rs
@@ -255,6 +255,31 @@ where
}
}
+/// Concatenates a list of [FormatElement]s with spaces and line breaks to fit
+/// them on as few lines as possible
+///
+/// ## Examples
+///
+/// ```rust
+/// use std::str::from_utf8;
+/// use rome_formatter::{fill_elements, FormatElement, space_token, token, format_element, FormatOptions};
+/// let a = from_utf8(&[b'a'; 30]).unwrap();
+/// let b = from_utf8(&[b'b'; 30]).unwrap();
+/// let c = from_utf8(&[b'c'; 30]).unwrap();
+/// let d = from_utf8(&[b'd'; 30]).unwrap();
+/// let expr = fill_elements([token(a), token(b), token(c), token(d)]);
+///
+/// assert_eq!(format!("{a} {b}\n{c} {d}"), format_element(&expr, FormatOptions::default()).into_code())
+/// ```
+pub fn fill_elements(elements: impl IntoIterator<Item = FormatElement>) -> FormatElement {
+ let mut list: Vec<_> = elements.into_iter().collect();
+ match list.len() {
+ 0 => empty_element(),
+ 1 => list.pop().unwrap(),
+ _ => FormatElement::Fill(List::new(list)),
+ }
+}
+
/// Joins the elements by placing a given separator between elements.
///
/// ## Examples
@@ -802,10 +827,13 @@ pub enum FormatElement {
/// Concatenates multiple elements together. See [concat_elements] and [join_elements] for examples.
List(List),
+ /// Concatenates multiple elements together with spaces or line breaks to fill the print width. See [fill_elements].
+ Fill(List),
+
/// A token that should be printed as is, see [token] for documentation and examples.
Token(Token),
- LineSuffix(Box<FormatElement>),
+ LineSuffix(Content),
}
impl Debug for FormatElement {
@@ -821,6 +849,10 @@ impl Debug for FormatElement {
write!(fmt, "List ")?;
content.fmt(fmt)
}
+ FormatElement::Fill(content) => {
+ write!(fmt, "Fill ")?;
+ content.fmt(fmt)
+ }
FormatElement::Token(content) => content.fmt(fmt),
FormatElement::LineSuffix(content) => {
fmt.debug_tuple("LineSuffix").field(content).finish()
@@ -895,6 +927,62 @@ impl List {
fn new(content: Vec<FormatElement>) -> Self {
Self { content }
}
+
+ fn trim_start(&self) -> Self {
+ let mut content: Vec<_> = self
+ .iter()
+ .skip_while(|e| match e {
+ FormatElement::Empty => true,
+ FormatElement::Space => true,
+ FormatElement::Line(_) => true,
+ FormatElement::Indent(_) => true,
+ FormatElement::Token(t) => {
+ let s = t.trim_start();
+ s.is_empty()
+ }
+ _ => false,
+ })
+ .map(Clone::clone)
+ .collect();
+
+ if let Some(FormatElement::Token(s)) = content.get_mut(0) {
+ *s = s.trim_start();
+ }
+
+ Self::new(content)
+ }
+
+ fn trim_end(&self) -> Self {
+ let idx_first_non_empty = self.iter().rev().position(|e| match e {
+ FormatElement::Empty => false,
+ FormatElement::Space => false,
+ FormatElement::Line(_) => false,
+ FormatElement::Indent(_) => false,
+ FormatElement::Token(t) => {
+ let s = t.trim_end();
+ !s.is_empty()
+ }
+ _ => true,
+ });
+
+ match idx_first_non_empty {
+ Some(idx_first_non_empty) => {
+ let idx_first_non_empty = self.len() - idx_first_non_empty;
+ let mut content: Vec<_> = self
+ .iter()
+ .take(idx_first_non_empty)
+ .map(Clone::clone)
+ .collect();
+
+ if let Some(FormatElement::Token(s)) = content.last_mut() {
+ *s = s.trim_end();
+ }
+
+ Self::new(content)
+ }
+ None => Self::new(vec![]),
+ }
+ }
}
impl Deref for List {
@@ -1118,28 +1206,9 @@ impl FormatElement {
FormatElement::Line(_) => FormatElement::Empty,
FormatElement::Indent(i) => i.content.trim_start(),
FormatElement::Group(g) => g.content.trim_start(),
+ FormatElement::Fill(list) => FormatElement::Fill(list.trim_start()),
FormatElement::ConditionalGroupContent(g) => g.content.trim_start(),
- FormatElement::List(list) => {
- let mut content: Vec<_> = list
- .iter()
- .skip_while(|e| match e {
- FormatElement::Empty => true,
- FormatElement::Space => true,
- FormatElement::Line(_) => true,
- FormatElement::Indent(_) => true,
- FormatElement::Token(t) => {
- let s = t.trim_start();
- s.is_empty()
- }
- _ => false,
- })
- .map(Clone::clone)
- .collect();
- if let Some(FormatElement::Token(s)) = content.get_mut(0) {
- *s = s.trim_start();
- }
- FormatElement::List(List::new(content))
- }
+ FormatElement::List(list) => FormatElement::List(list.trim_start()),
FormatElement::Token(s) => FormatElement::Token(s.trim_start()),
FormatElement::LineSuffix(s) => FormatElement::LineSuffix(Box::new(s.trim_start())),
}
@@ -1156,35 +1225,8 @@ impl FormatElement {
FormatElement::Indent(i) => i.content.trim_end(),
FormatElement::Group(g) => g.content.trim_end(),
FormatElement::ConditionalGroupContent(g) => g.content.trim_end(),
- FormatElement::List(list) => {
- let idx_first_non_empty = list.iter().rev().position(|e| match e {
- FormatElement::Empty => false,
- FormatElement::Space => false,
- FormatElement::Line(_) => false,
- FormatElement::Indent(_) => false,
- FormatElement::Token(t) => {
- let s = t.trim_end();
- !s.is_empty()
- }
- _ => true,
- });
-
- match idx_first_non_empty {
- Some(idx_first_non_empty) => {
- let idx_first_non_empty = list.len() - idx_first_non_empty;
- let mut content: Vec<_> = list
- .iter()
- .take(idx_first_non_empty)
- .map(Clone::clone)
- .collect();
- if let Some(FormatElement::Token(s)) = content.last_mut() {
- *s = s.trim_end();
- }
- FormatElement::List(List::new(content))
- }
- None => FormatElement::List(List::new(vec![])),
- }
- }
+ FormatElement::Fill(list) => FormatElement::Fill(list.trim_end()),
+ FormatElement::List(list) => FormatElement::List(list.trim_end()),
FormatElement::Token(s) => FormatElement::Token(s.trim_end()),
FormatElement::LineSuffix(s) => FormatElement::LineSuffix(Box::new(s.trim_end())),
}

MODIFY
crates/rome_formatter/src/js/lists/array_element_list.rs
crates/rome_formatter/src/js/lists/array_element_list.rs
+use std::convert::Infallible;
+
use crate::{
+ fill_elements,
format_element::join_elements_soft_line,
format_elements,
formatter_traits::{FormatOptionalTokenAndNode, FormatTokenAndNode},
- if_group_breaks, token, FormatElement, FormatResult, Formatter, ToFormatElement,
+ if_group_breaks, token,
+ utils::has_formatter_trivia,
+ FormatElement, FormatResult, Formatter, ToFormatElement,
};
use rslint_parser::{
- ast::{JsAnyArrayElement, JsArrayElementList},
- AstSeparatedList,
+ ast::{JsAnyArrayElement, JsAnyExpression, JsArrayElementList},
+ AstNode, AstSeparatedList,
};
impl ToFormatElement for JsArrayElementList {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
+ if !has_formatter_trivia(self.syntax()) && can_print_fill(self) {
+ return Ok(fill_elements(
+ // Using format_separated is valid in this case as can_print_fill does not allow holes
+ formatter.format_separated(self.clone(), || token(","))?,
+ ));
+ }
+
// Specifically do not use format_separated as array expressions need
// separators inserted after empty expressions regardless of the
// formatting since this makes a semantic difference
@@ -41,3 +53,52 @@ impl ToFormatElement for JsArrayElementList {
Ok(join_elements_soft_line(results))
}
}
+
+/// Returns true if the provided JsArrayElementList could
+/// be "fill-printed" instead of breaking each element on
+/// a different line.
+///
+/// The underlying logic only allows lists of literal expressions
+/// with 10 or less characters, potentially wrapped in a "short"
+/// unary expression (+, -, ~ or !)
+fn can_print_fill(list: &JsArrayElementList) -> bool {
+ use rslint_parser::ast::JsAnyArrayElement::*;
+ use rslint_parser::ast::JsAnyExpression::*;
+ use rslint_parser::ast::JsUnaryOperation::*;
+
+ list.iter().all(|item| match item {
+ Ok(JsAnyExpression(JsUnaryExpression(expr))) => {
+ match expr.operation() {
+ Ok(Plus | Minus | BitwiseNot | LogicalNot) => {}
+ _ => return false,
+ }
+
+ if let Ok(expr) = expr.argument() {
+ is_short_literal(&expr)
+ } else {
+ false
+ }
+ }
+ Ok(JsAnyExpression(expr)) => is_short_literal(&expr),
+ _ => false,
+ })
+}
+
+/// Returns true if the provided expression is a literal with 10 or less characters
+fn is_short_literal(expr: &JsAnyExpression) -> bool {
+ match expr {
+ JsAnyExpression::JsAnyLiteralExpression(lit) => {
+ let token_len = lit
+ .syntax()
+ .text()
+ .try_fold_chunks::<_, _, Infallible>(0, |sum, chunk| {
+ // Count actual characters instead of byte length
+ Ok(sum + chunk.chars().count())
+ })
+ .expect("the above fold operation is infallible");
+
+ token_len <= 10
+ }
+ _ => false,
+ }
+}

MODIFY
crates/rome_formatter/src/lib.rs
crates/rome_formatter/src/lib.rs
@@ -66,10 +66,10 @@ use rslint_parser::{parse, Syntax, SyntaxError, SyntaxNode};
use std::fmt::Display;
pub use format_element::{
- block_indent, concat_elements, empty_element, empty_line, group_elements, hard_line_break,
- if_group_breaks, if_group_fits_on_single_line, indent, join_elements, join_elements_hard_line,
- line_suffix, soft_block_indent, soft_line_break, soft_line_break_or_space,
- soft_line_indent_or_space, space_token, token, FormatElement, Token,
+ block_indent, concat_elements, empty_element, empty_line, fill_elements, group_elements,
+ hard_line_break, if_group_breaks, if_group_fits_on_single_line, indent, join_elements,
+ join_elements_hard_line, line_suffix, soft_block_indent, soft_line_break,
+ soft_line_break_or_space, soft_line_indent_or_space, space_token, token, FormatElement, Token,
};
pub use printer::Printer;
pub use printer::PrinterOptions;

MODIFY
crates/rome_formatter/src/printer.rs
crates/rome_formatter/src/printer.rs
@@ -2,8 +2,12 @@ use std::iter::once;
use rome_rowan::TextSize;
-use crate::format_element::{ConditionalGroupContent, Group, GroupPrintMode, LineMode};
-use crate::{FormatElement, FormatOptions, Formatted, IndentStyle, SourceMarker};
+use crate::format_element::{ConditionalGroupContent, Group, GroupPrintMode, LineMode, List};
+use crate::intersperse::Intersperse;
+use crate::{
+ hard_line_break, space_token, FormatElement, FormatOptions, Formatted, IndentStyle,
+ SourceMarker,
+};
/// Options that affect how the [Printer] prints the format tokens
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -115,7 +119,11 @@ impl<'a> Printer<'a> {
queue.enqueue(PrintElementCall::new(element, PrintElementArgs { indent }));
while let Some(print_element_call) = queue.dequeue() {
- queue.extend(self.print_element(print_element_call.element, print_element_call.args));
+ self.print_element(
+ &mut queue,
+ print_element_call.element,
+ print_element_call.args,
+ );
if queue.is_empty() && !self.state.line_suffixes.is_empty() {
queue.extend(self.state.line_suffixes.drain(..));
@@ -125,20 +133,20 @@ impl<'a> Printer<'a> {
Formatted::new(self.state.buffer, None, self.state.source_markers)
}
- /// Prints a single element and returns the elements to queue (that should be printed next).
+ /// Prints a single element and push the following elements to queue
fn print_element(
&mut self,
+ queue: &mut ElementCallQueue<'a>,
element: &'a FormatElement,
args: PrintElementArgs,
- ) -> Vec<PrintElementCall<'a>> {
+ ) {
match element {
FormatElement::Space => {
if self.state.line_width > 0 {
self.state.pending_space = true;
}
- vec![]
}
- FormatElement::Empty => vec![],
+ FormatElement::Empty => {}
FormatElement::Token(token) => {
// Print pending indention
if self.state.pending_indent > 0 {
@@ -165,52 +173,50 @@ impl<'a> Printer<'a> {
}
self.print_str(token);
- vec![]
}
FormatElement::Group(Group { content }) => {
- match self.try_print_flat(element, args.clone()) {
- Err(_) => {
+ if self.try_print_flat(queue, element, args.clone()).is_err() {
// Flat printing didn't work, print with line breaks
- vec![PrintElementCall::new(content.as_ref(), args)]
+ queue.enqueue(PrintElementCall::new(content.as_ref(), args));
}
- Ok(_) => vec![],
}
+
+ FormatElement::Fill(list) => {
+ self.print_fill(queue, list, args);
}
- FormatElement::List(list) => list
- .iter()
- .map(|t| PrintElementCall::new(t, args.clone()))
- .collect(),
+ FormatElement::List(list) => {
+ queue.extend(list.iter().map(|t| PrintElementCall::new(t, args.clone())));
+ }
FormatElement::Indent(indent) => {
- vec![PrintElementCall::new(
+ queue.enqueue(PrintElementCall::new(
&indent.content,
args.with_incremented_indent(),
- )]
+ ));
}
FormatElement::ConditionalGroupContent(ConditionalGroupContent {
mode: GroupPrintMode::Multiline,
content,
}) => {
- vec![PrintElementCall::new(content, args)]
+ queue.enqueue(PrintElementCall::new(content, args));
}
FormatElement::ConditionalGroupContent(ConditionalGroupContent {
mode: GroupPrintMode::Flat,
..
- }) => {
- vec![]
- }
+ }) => {}
FormatElement::Line(line) => {
if !self.state.line_suffixes.is_empty() {
+ queue.extend(
self.state
.line_suffixes
.drain(..)
- .chain(once(PrintElementCall::new(element, args)))
- .collect()
+ .chain(once(PrintElementCall::new(element, args))),
+ );
} else {
// Only print a newline if the current line isn't already empty
if self.state.line_width > 0 {
@@ -224,7 +230,6 @@ impl<'a> Printer<'a> {
self.state.pending_space = false;
self.state.pending_indent = args.indent;
- vec![]
}
}
@@ -232,7 +237,6 @@ impl<'a> Printer<'a> {
self.state
.line_suffixes
.push(PrintElementCall::new(&**suffix, args));
- vec![]
}
}
}
@@ -242,22 +246,27 @@ impl<'a> Printer<'a> {
/// or printing the group exceeds the configured maximal print width.
fn try_print_flat(
&mut self,
+ queue: &mut ElementCallQueue<'a>,
element: &'a FormatElement,
args: PrintElementArgs,
) -> Result<(), LineBreakRequiredError> {
let snapshot = self.state.snapshot();
+ let min_queue_length = queue.0.len();
- let mut queue = ElementCallQueue::new();
queue.enqueue(PrintElementCall::new(element, args));
while let Some(call) = queue.dequeue() {
- match self.try_print_flat_element(call.element, call.args) {
- Ok(to_queue) => queue.extend(to_queue),
- Err(err) => {
+ if let Err(err) = self.try_print_flat_element(queue, call.element, call.args) {
self.state.restore(snapshot);
+ queue.0.truncate(min_queue_length);
return Err(err);
}
+
+ if queue.0.len() == min_queue_length {
+ break;
}
+
+ debug_assert!(queue.0.len() > min_queue_length);
}
Ok(())
@@ -265,15 +274,16 @@ impl<'a> Printer<'a> {
fn try_print_flat_element(
&mut self,
+ queue: &mut ElementCallQueue<'a>,
element: &'a FormatElement,
args: PrintElementArgs,
- ) -> Result<Vec<PrintElementCall<'a>>, LineBreakRequiredError> {
- let next_calls = match element {
+ ) -> Result<(), LineBreakRequiredError> {
+ match element {
FormatElement::Token(_) => {
let current_line = self.state.generated_line;
// Delegate to generic string printing
- let calls = self.print_element(element, args);
+ self.print_element(queue, element, args);
// If the line is too long, break the group
if self.state.line_width > self.options.print_width as usize {
@@ -284,8 +294,6 @@ impl<'a> Printer<'a> {
if current_line != self.state.generated_line {
return Err(LineBreakRequiredError);
}
-
- calls
}
FormatElement::Line(line) => {
match line.mode {
@@ -293,38 +301,110 @@ impl<'a> Printer<'a> {
if self.state.line_width > 0 {
self.state.pending_space = true;
}
- vec![]
}
// We want a flat structure, so omit soft line wraps
- LineMode::Soft => vec![],
+ LineMode::Soft => {}
LineMode::Hard | LineMode::Empty => return Err(LineBreakRequiredError),
}
}
FormatElement::Group(group) => {
- vec![PrintElementCall::new(group.content.as_ref(), args)]
+ queue.enqueue(PrintElementCall::new(group.content.as_ref(), args))
+ }
+
+ // Fill elements are printed as space-separated lists in flat mode
+ FormatElement::Fill(list) => {
+ // Intersperse the list of elements with spaces before pushing
+ // them to the queue, however elements in the queue are stored
+ // as references so the space element must be allocated in a
+ // static so its reference is bound to the static lifetime
+ static SPACE: FormatElement = space_token();
+ queue.0.extend(
+ Intersperse::new(list.iter().rev(), &SPACE)
+ .map(|t| PrintElementCall::new(t, args.clone())),
+ );
}
FormatElement::ConditionalGroupContent(ConditionalGroupContent {
mode: GroupPrintMode::Flat,
content,
- }) => vec![PrintElementCall::new(content, args)],
+ }) => queue.enqueue(PrintElementCall::new(content, args)),
// Omit if there's no flat_contents
FormatElement::ConditionalGroupContent(ConditionalGroupContent {
mode: GroupPrintMode::Multiline,
..
- }) => vec![],
+ }) => {}
FormatElement::LineSuffix { .. } => return Err(LineBreakRequiredError),
FormatElement::Empty
| FormatElement::Space
| FormatElement::Indent { .. }
- | FormatElement::List { .. } => self.print_element(element, args),
- };
+ | FormatElement::List { .. } => self.print_element(queue, element, args),
+ }
+
+ Ok(())
+ }
+
+ /// Print a list in fill mode.
+ ///
+ /// Prints the elements of the list separated by spaces, but backtrack if
+ /// they go over the print width and insert a line break before resuming
+ /// printing
+ fn print_fill(
+ &mut self,
+ queue: &mut ElementCallQueue<'a>,
+ content: &'a List,
+ args: PrintElementArgs,
+ ) {
+ let mut snapshot = None;
- Ok(next_calls)
+ for item in content.iter() {
+ if snapshot.is_some() {
+ self.state.pending_space = true;
+ }
+
+ self.print_all(queue, item, args.clone());
+
+ if self.state.line_width > self.options.print_width.into() {
+ if let Some(snapshot) = snapshot.take() {
+ self.state.restore(snapshot);
+
+ static LINE: FormatElement = hard_line_break();
+ self.print_all(queue, &LINE, args.clone());
+
+ self.print_all(queue, item, args.clone());
+ }
+ }
+
+ snapshot = Some(self.state.snapshot());
+ }
+ }
+
+ /// Fully print an element (print the element itself and all its descendants)
+ ///
+ /// Unlike [print_element], this function ensures the entire element has
+ /// been printed when it returns and the queue is back to its original state
+ fn print_all(
+ &mut self,
+ queue: &mut ElementCallQueue<'a>,
+ element: &'a FormatElement,
+ args: PrintElementArgs,
+ ) {
+ let min_queue_length = queue.0.len();
+
+ queue.enqueue(PrintElementCall::new(element, args));
+
+ while let Some(call) = queue.dequeue() {
+ self.print_element(queue, call.element, call.args);
+
+ if queue.0.len() == min_queue_length {
+ return;
+ }
+
+ debug_assert!(queue.0.len() > min_queue_length);
+ }
}
fn print_str(&mut self, content: &str) {

MODIFY
crates/rome_formatter/src/utils.rs
crates/rome_formatter/src/utils.rs
@@ -4,7 +4,7 @@ use crate::{
Formatter,
};
use rslint_parser::ast::JsInitializerClause;
-use rslint_parser::SyntaxToken;
+use rslint_parser::{SyntaxNode, SyntaxNodeExt, SyntaxToken};
/// Utility function to format the separators of the nodes that belong to the unions
/// of [rslint_parser::ast::TsAnyTypeMember].
@@ -43,3 +43,39 @@ pub(crate) fn format_interpreter(
empty_element,
)
}
+
+/// Returns true if this node contains "printable" trivias: comments
+/// or empty lines (2 consecutive newlines only separated by whitespace)
+pub(crate) fn has_formatter_trivia(node: &SyntaxNode) -> bool {
+ let mut line_count = 0;
+
+ for token in node.tokens() {
+ for trivia in token.leading_trivia().pieces() {
+ if trivia.as_comments().is_some() {
+ return true;
+ } else if trivia.as_newline().is_some() {
+ line_count += 1;
+ if line_count >= 2 {
+ return true;
+ }
+ }
+ }
+
+ // This is where the token would be,
+ // reset the consecutive newline counter
+ line_count = 0;
+
+ for trivia in token.trailing_trivia().pieces() {
+ if trivia.as_comments().is_some() {
+ return true;
+ } else if trivia.as_newline().is_some() {
+ line_count += 1;
+ if line_count >= 2 {
+ return true;
+ }
+ }
+ }
+ }
+
+ false
+}

MODIFY
crates/rome_formatter/tests/specs/prettier/arrays/numbers-in-args.js.snap
crates/rome_formatter/tests/specs/prettier/arrays/numbers-in-args.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 57
+assertion_line: 121
expression: numbers-in-args.js
---
@@ -30,106 +30,12 @@ expect(bifornCringerMoshedPerplexSawder.getArrayOfNumbers()).toEqual(
expect(bifornCringerMoshedPerplexSawder.getLongArrayOfNumbers()).toEqual(
[
- 66,
- 57,
- 45,
- 47,
- 33,
- 53,
- 82,
- 81,
- 76,
- 78,
- 10,
- 78,
- 15,
- 98,
- 24,
- 29,
- 32,
- 27,
- 28,
- 76,
- 41,
- 65,
- 84,
- 35,
- 97,
- 90,
- 75,
- 24,
- 88,
- 45,
- 23,
- 75,
- 63,
- 86,
- 24,
- 39,
- 9,
- 51,
- 33,
- 40,
- 58,
- 17,
- 49,
- 86,
- 63,
- 59,
- 97,
- 91,
- 98,
- 99,
- 5,
- 69,
- 51,
- 44,
- 34,
- 69,
- 17,
- 91,
- 27,
- 83,
- 26,
- 34,
- 93,
- 29,
- 66,
- 88,
- 49,
- 33,
- 49,
- 73,
- 9,
- 81,
- 4,
- 36,
- 5,
- 14,
- 43,
- 31,
- 86,
- 27,
- 39,
- 75,
- 98,
- 99,
- 55,
- 19,
- 39,
- 21,
- 85,
- 86,
- 46,
- 82,
- 11,
- 44,
- 48,
- 77,
- 35,
- 48,
- 78,
- 97,
+ 66, 57, 45, 47, 33, 53, 82, 81, 76, 78, 10, 78, 15, 98, 24, 29, 32, 27, 28,
+ 76, 41, 65, 84, 35, 97, 90, 75, 24, 88, 45, 23, 75, 63, 86, 24, 39, 9, 51,
+ 33, 40, 58, 17, 49, 86, 63, 59, 97, 91, 98, 99, 5, 69, 51, 44, 34, 69, 17,
+ 91, 27, 83, 26, 34, 93, 29, 66, 88, 49, 33, 49, 73, 9, 81, 4, 36, 5, 14, 43,
+ 31, 86, 27, 39, 75, 98, 99, 55, 19, 39, 21, 85, 86, 46, 82, 11, 44, 48, 77,
+ 35, 48, 78, 97,
],
);

MODIFY
crates/rome_formatter/tests/specs/prettier/arrays/numbers-in-assignment.js.snap
crates/rome_formatter/tests/specs/prettier/arrays/numbers-in-assignment.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 57
+assertion_line: 121
expression: numbers-in-assignment.js
---
@@ -31,106 +31,12 @@ bifornCringerMoshedPerplex.bifornCringerMoshedPerplexSawder.arrayOfNumbers =
bifornCringerMoshedPerplex.bifornCringerMoshedPerplexSawder.arrayOfNumbers2 =
[
- 66,
- 57,
- 45,
- 47,
- 33,
- 53,
- 82,
- 81,
- 76,
- 78,
- 10,
- 78,
- 15,
- 98,
- 24,
- 29,
- 32,
- 27,
- 28,
- 76,
- 41,
- 65,
- 84,
- 35,
- 97,
- 90,
- 75,
- 24,
- 88,
- 45,
- 23,
- 75,
- 63,
- 86,
- 24,
- 39,
- 9,
- 51,
- 33,
- 40,
- 58,
- 17,
- 49,
- 86,
- 63,
- 59,
- 97,
- 91,
- 98,
- 99,
- 5,
- 69,
- 51,
- 44,
- 34,
- 69,
- 17,
- 91,
- 27,
- 83,
- 26,
- 34,
- 93,
- 29,
- 66,
- 88,
- 49,
- 33,
- 49,
- 73,
- 9,
- 81,
- 4,
- 36,
- 5,
- 14,
- 43,
- 31,
- 86,
- 27,
- 39,
- 75,
- 98,
- 99,
- 55,
- 19,
- 39,
- 21,
- 85,
- 86,
- 46,
- 82,
- 11,
- 44,
- 48,
- 77,
- 35,
- 48,
- 78,
- 97,
+ 66, 57, 45, 47, 33, 53, 82, 81, 76, 78, 10, 78, 15, 98, 24, 29, 32, 27, 28,
+ 76, 41, 65, 84, 35, 97, 90, 75, 24, 88, 45, 23, 75, 63, 86, 24, 39, 9, 51,
+ 33, 40, 58, 17, 49, 86, 63, 59, 97, 91, 98, 99, 5, 69, 51, 44, 34, 69, 17,
+ 91, 27, 83, 26, 34, 93, 29, 66, 88, 49, 33, 49, 73, 9, 81, 4, 36, 5, 14, 43,
+ 31, 86, 27, 39, 75, 98, 99, 55, 19, 39, 21, 85, 86, 46, 82, 11, 44, 48, 77,
+ 35, 48, 78, 97,
];
```

MODIFY
crates/rome_formatter/tests/specs/prettier/arrays/numbers-trailing-comma.js.snap
crates/rome_formatter/tests/specs/prettier/arrays/numbers-trailing-comma.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 57
+assertion_line: 121
expression: numbers-trailing-comma.js
---
@@ -18,24 +18,7 @@ c = [
// --------------- print-width -------------------------------------------------
c =
[
- 66,
- 66,
- 57,
- 45,
- 47,
- 33,
- 53,
- 82,
- 81,
- 76,
- 66,
- 57,
- 45,
- 47,
- 33,
- 53,
- 82,
- 81,
+ 66, 66, 57, 45, 47, 33, 53, 82, 81, 76, 66, 57, 45, 47, 33, 53, 82, 81,
223323,
];

MODIFY
crates/rome_formatter/tests/specs/prettier/arrays/numbers3.js.snap
crates/rome_formatter/tests/specs/prettier/arrays/numbers3.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 57
+assertion_line: 121
expression: numbers3.js
---
@@ -29,106 +29,12 @@ let test_case = [
```js
let test_case = [
[
- 66,
- 57,
- 45,
- 47,
- 33,
- 53,
- 82,
- 81,
- 76,
- 78,
- 10,
- 78,
- 15,
- 98,
- 24,
- 29,
- 32,
- 27,
- 28,
- 76,
- 41,
- 65,
- 84,
- 35,
- 97,
- 90,
- 75,
- 24,
- 88,
- 45,
- 23,
- 75,
- 63,
- 86,
- 24,
- 39,
- 9,
- 51,
- 33,
- 40,
- 58,
- 17,
- 49,
- 86,
- 63,
- 59,
- 97,
- 91,
- 98,
- 99,
- 5,
- 69,
- 51,
- 44,
- 34,
- 69,
- 17,
- 91,
- 27,
- 83,
- 26,
- 34,
- 93,
- 29,
- 66,
- 88,
- 49,
- 33,
- 49,
- 73,
- 9,
- 81,
- 4,
- 36,
- 5,
- 14,
- 43,
- 31,
- 86,
- 27,
- 39,
- 75,
- 98,
- 99,
- 55,
- 19,
- 39,
- 21,
- 85,
- 86,
- 46,
- 82,
- 11,
- 44,
- 48,
- 77,
- 35,
- 48,
- 78,
- 97,
+ 66, 57, 45, 47, 33, 53, 82, 81, 76, 78, 10, 78, 15, 98, 24, 29, 32, 27, 28,
+ 76, 41, 65, 84, 35, 97, 90, 75, 24, 88, 45, 23, 75, 63, 86, 24, 39, 9, 51,
+ 33, 40, 58, 17, 49, 86, 63, 59, 97, 91, 98, 99, 5, 69, 51, 44, 34, 69, 17,
+ 91, 27, 83, 26, 34, 93, 29, 66, 88, 49, 33, 49, 73, 9, 81, 4, 36, 5, 14, 43,
+ 31, 86, 27, 39, 75, 98, 99, 55, 19, 39, 21, 85, 86, 46, 82, 11, 44, 48, 77,
+ 35, 48, 78, 97,
],
[
41,

MODIFY
crates/rome_formatter/tests/specs/prettier/function-single-destructuring/array.js.snap
crates/rome_formatter/tests/specs/prettier/function-single-destructuring/array.js.snap
---
source: crates/rome_formatter/tests/prettier_tests.rs
-assertion_line: 57
+assertion_line: 121
expression: array.js
---
@@ -48,11 +48,7 @@ function excludeFirstFiveResults2(
function excludeFirstFiveResults3(
[firstResult, secondResult, thirdResult, fourthResult, fifthResult, ...rest] = [
- 1,
- 2,
- 3,
- 4,
- 5,
+ 1, 2, 3, 4, 5,
],
) {
return rest;

MODIFY
crates/rome_formatter/tests/specs/prettier/trailing-comma/trailing_whitespace.js.snap
crates/rome_formatter/tests/specs/prettier/trailing-comma/trailing_whitespace.js.snap
@@ -55,8 +55,7 @@ this.getAttribute(function(s) /*string*/ {
# Output
```js
let example = [
- "FOO",
- "BAR",
+ "FOO", "BAR",
// Comment
];

feat(rome_formatter): implement fill-printing for array expressions (#2104)