diff --git a/crates/rome_cli/examples/input.js b/crates/rome_cli/examples/input.js index 4e5b6b5ead9..e91bdf2e8f4 100644 --- a/crates/rome_cli/examples/input.js +++ b/crates/rome_cli/examples/input.js @@ -1,4 +1,54 @@ -function foo() { let var1 = [true, false] - let broken = [ 45, 54] - let var2 = (var1, var2) => {} -} +tap.test( + "RecordImport.advance", (t) => { + mockFS( + (callback) => { + batch.setResults( + [fs.createReadStream(dataFile)], (err) => { + getBatches( + (err, batches) => { + checkStates(batches, ["started"]); + + RecordImport.advance( + (err) => { + t.error(err, "Error should be empty."); + + getBatches( + (err, batches) => { + checkStates(batches, ["process.completed"]); + + // Need to manually move to the next step + batch.importRecords( + (err) => { + t.error(err, "Error should be empty."); + + getBatches( + (err, batches) => { + checkStates(batches, ["import.completed"]); + + RecordImport.advance( + (err) => { + t.error(err, "Error should be empty."); + }, + ); + + t.ok(batch.getCurState().name(i18n)); + }, + ); + }, + ); + + t.ok(batch.getCurState().name(i18n)); + }, + ); + }, + ); + + t.ok(batch.getCurState().name(i18n)); + }, + ); + }, + ); + }, + ); + }, +); diff --git a/crates/rome_formatter/src/format_element.rs b/crates/rome_formatter/src/format_element.rs index bb4565d1010..6d9013e6324 100644 --- a/crates/rome_formatter/src/format_element.rs +++ b/crates/rome_formatter/src/format_element.rs @@ -5,6 +5,7 @@ use rome_rowan::SyntaxTokenText; use std::borrow::Cow; use std::fmt::{self, Debug, Formatter}; use std::ops::Deref; +use std::rc::Rc; type Content = Box; @@ -65,6 +66,10 @@ pub enum FormatElement { /// A list of different variants representing the same content. The printer picks the best fitting content. /// Line breaks inside of a best fitting don't propagate to parent groups. BestFitting(BestFitting), + + /// Reference counted format element content. Useful when the same content must be emitted twice + /// because it avoids deep cloning of the inner content and instead only requires bumping a ref counter. + Rc(Rc), } #[derive(Clone, Copy, Eq, PartialEq, Debug)] @@ -144,6 +149,7 @@ impl Debug for FormatElement { best_fitting.fmt(fmt) } FormatElement::ExpandParent => write!(fmt, "ExpandParent"), + FormatElement::Rc(inner) => inner.fmt(fmt), } } } @@ -464,6 +470,7 @@ impl FormatElement { pub fn is_empty(&self) -> bool { match self { FormatElement::List(list) => list.is_empty(), + FormatElement::Rc(inner) => inner.is_empty(), _ => false, } } @@ -491,6 +498,7 @@ impl FormatElement { FormatElement::BestFitting(_) => false, FormatElement::LineSuffixBoundary => false, FormatElement::ExpandParent => true, + FormatElement::Rc(inner) => inner.will_break(), } } diff --git a/crates/rome_formatter/src/format_extensions.rs b/crates/rome_formatter/src/format_extensions.rs index 73b4128e79a..b61fb585694 100644 --- a/crates/rome_formatter/src/format_extensions.rs +++ b/crates/rome_formatter/src/format_extensions.rs @@ -1,6 +1,7 @@ use crate::prelude::*; use std::cell::RefCell; use std::marker::PhantomData; +use std::rc::Rc; use crate::{write, Buffer, VecBuffer}; @@ -118,15 +119,15 @@ pub trait MemoizeFormat { /// /// // Calls `format` for everytime the object gets formatted /// assert_eq!( - /// format!(SimpleFormatContext::default(), [token("Formatted 1 times."), token("Formatted 2 times.")]), - /// format!(SimpleFormatContext::default(), [normal, normal]) + /// "Formatted 1 times. Formatted 2 times.", + /// format!(SimpleFormatContext::default(), [normal, space_token(), normal]).unwrap().print().as_code() /// ); /// /// // Memoized memoizes the result and calls `format` only once. /// let memoized = normal.memoized(); /// assert_eq!( - /// format!(SimpleFormatContext::default(), [token("Formatted 3 times."), token("Formatted 3 times.")]), - /// format![SimpleFormatContext::default(), [memoized, memoized]] + /// "Formatted 3 times. Formatted 3 times.", + /// format![SimpleFormatContext::default(), [memoized, space_token(), memoized]].unwrap().print().as_code() /// ); /// ``` /// @@ -141,9 +142,10 @@ pub trait MemoizeFormat { impl MemoizeFormat for T where T: Format {} /// Memoizes the output of its inner [Format] to avoid re-formatting a potential expensive object. +#[derive(Debug)] pub struct Memoized { inner: F, - memory: RefCell>>>, + memory: RefCell>>>, options: PhantomData, } @@ -169,9 +171,7 @@ where if let Some(memory) = self.memory.borrow().as_ref() { return match memory { Ok(elements) => { - for element in elements { - f.write_element(element.clone())?; - } + f.write_element(FormatElement::Rc(elements.clone()))?; Ok(()) } @@ -184,12 +184,10 @@ where match result { Ok(_) => { - let elements = buffer.into_vec(); - for element in &elements { - f.write_element(element.clone())?; - } - - *self.memory.borrow_mut() = Some(Ok(elements)); + let elements = buffer.into_element(); + let reference = Rc::new(elements); + f.write_element(FormatElement::Rc(reference.clone()))?; + *self.memory.borrow_mut() = Some(Ok(reference)); Ok(()) } diff --git a/crates/rome_formatter/src/printed_tokens.rs b/crates/rome_formatter/src/printed_tokens.rs index 92b64df6267..bcd8e001546 100644 --- a/crates/rome_formatter/src/printed_tokens.rs +++ b/crates/rome_formatter/src/printed_tokens.rs @@ -36,7 +36,9 @@ impl PrintedTokens { match (descendants.next(), offsets.next()) { (Some(descendant), Some(offset)) => match descendant.text_trimmed_range().start() { descendant_offset if descendant_offset < *offset => { - panic!("token has not been seen by the formatter: {descendant:#?}.\nUse `formatter.format_replaced` if you intentionally remove or replace a token from the formatted output.") + panic!("token has not been seen by the formatter: {descendant:#?}.\ + \nUse `format_replaced` if you want to replace a token from the formatted output.\ + \nUse `format_removed` if you to remove a token from the formatted output") } descendant_offset if descendant_offset > *offset => { panic!("tracked offset {offset:?} doesn't match any token of {root:#?}. Have you passed a token from another tree?"); diff --git a/crates/rome_formatter/src/printer/mod.rs b/crates/rome_formatter/src/printer/mod.rs index 7fda04ee003..32f04d0e881 100644 --- a/crates/rome_formatter/src/printer/mod.rs +++ b/crates/rome_formatter/src/printer/mod.rs @@ -282,7 +282,6 @@ impl<'a> Printer<'a> { if fits_on_line(&[variant], args.with_print_mode(mode), queue, self) { self.state.measured_group_fits = true; - queue.enqueue(PrintElementCall::new( variant, args.with_print_mode(mode), @@ -294,6 +293,7 @@ impl<'a> Printer<'a> { } } } + FormatElement::Rc(content) => queue.enqueue(PrintElementCall::new(content, args)), } } @@ -800,6 +800,7 @@ fn fits_element_on_line<'a, 'rest>( return Fits::No; } } + FormatElement::Rc(content) => queue.enqueue(PrintElementCall::new(content, args)), } Fits::Maybe diff --git a/crates/rome_js_formatter/src/builders.rs b/crates/rome_js_formatter/src/builders.rs index f99790f76a2..b4c979a6d51 100644 --- a/crates/rome_js_formatter/src/builders.rs +++ b/crates/rome_js_formatter/src/builders.rs @@ -3,7 +3,7 @@ use crate::{AsFormat, JsCommentStyle}; use rome_formatter::token::{ format_token_trailing_trivia, FormatInserted, FormatInsertedCloseParen, FormatInsertedOpenParen, FormatLeadingTrivia, FormatOnlyIfBreaks, FormatRemoved, - FormatReplaced, TriviaPrintMode, + FormatReplaced, }; use rome_formatter::{format_args, write, Argument, Arguments, GroupId, PreambleBuffer, VecBuffer}; use rome_js_syntax::{JsLanguage, JsSyntaxKind, JsSyntaxNode, JsSyntaxToken}; @@ -410,38 +410,17 @@ impl Format for FormatDelimited<'_, '_> { mode, } = self; - f.state_mut().track_token(open_token); - f.state_mut().track_token(close_token); + let open_delimiter = format_open_delimiter(open_token); + let close_delimiter = format_close_delimiter(close_token); - format_leading_trivia(open_token).fmt(f)?; + open_delimiter.format_leading_trivia().fmt(f)?; - let open_token_trailing_trivia = format_with(|f| { - // Not really interested in the pre-amble, but want to know if it was written - let mut buffer = VecBuffer::new(f.state_mut()); - - write!(buffer, [format_trailing_trivia(open_token)])?; - - let trivia = buffer.into_vec(); - - if !trivia.is_empty() { - f.write_elements(trivia)?; - soft_line_break().fmt(f)?; - } - - Ok(()) - }); - - let close_token_leading_trivia = format_with(|f| { - let mut buffer = PreambleBuffer::new(f, soft_line_break()); + let open_token_trailing_trivia = open_delimiter.format_trailing_trivia(); - write!( - buffer, - [format_leading_trivia(close_token).with_trim_mode(TriviaPrintMode::Trim)] - ) - }); + let close_token_leading_trivia = close_delimiter.format_leading_trivia(); let delimited = format_with(|f| { - format_trimmed_token(open_token).fmt(f)?; + open_delimiter.format_token().fmt(f)?; let format_content = format_with(|f| f.write_fmt(Arguments::from(content))); @@ -484,7 +463,7 @@ impl Format for FormatDelimited<'_, '_> { } }; - format_trimmed_token(close_token).fmt(f) + close_delimiter.format_token().fmt(f) }); let _grouped = match mode { @@ -511,3 +490,95 @@ enum DelimitedMode { SoftBlockIndent(Option), SoftBlockSpaces(Option), } + +/// Use this function to create an open delimiter, where you can extract the formatting of +/// trivias and token, separately. +/// +/// This function assumes that you will use the token to replicate [format_delimited], which means +/// that it will add possible line breaks +pub(crate) fn format_open_delimiter(open_token: &JsSyntaxToken) -> OpenDelimiter { + OpenDelimiter::new(open_token) +} + +/// Use this function to create an close delimiter, where you can extract the formatting of +/// trivias and token, separately. +/// +/// This function assumes that you will use the token to replicate [format_delimited], which means +/// that it will add possible line breaks +pub(crate) fn format_close_delimiter(close_token: &JsSyntaxToken) -> CloseDelimiter { + CloseDelimiter::new(close_token) +} + +pub(crate) struct OpenDelimiter<'t> { + open_token: &'t JsSyntaxToken, +} + +impl<'t> OpenDelimiter<'t> { + pub(crate) fn new(open_token: &'t JsSyntaxToken) -> Self { + Self { open_token } + } + + /// It extracts the formatted leading trivia of the token, without writing it in the buffer + pub(crate) fn format_leading_trivia(&self) -> impl Format + 't { + format_leading_trivia(self.open_token) + } + + /// It extracts the formatted trailing trivia of the token, without writing it in the buffer + pub(crate) fn format_trailing_trivia(&self) -> impl Format + 't { + format_with(|f| { + // Not really interested in the pre-amble, but want to know if it was written + let mut buffer = VecBuffer::new(f.state_mut()); + + write!(buffer, [format_trailing_trivia(self.open_token)])?; + + let trivia = buffer.into_vec(); + + if !trivia.is_empty() { + f.write_elements(trivia)?; + soft_line_break().fmt(f)?; + } + + Ok(()) + }) + } + + /// It extracts the formatted token, without writing it in the buffer + pub(crate) fn format_token(&self) -> impl Format + 't { + format_with(|f| { + f.state_mut().track_token(self.open_token); + write!(f, [format_trimmed_token(self.open_token)]) + }) + } +} + +pub(crate) struct CloseDelimiter<'t> { + close_token: &'t JsSyntaxToken, +} + +impl<'t> CloseDelimiter<'t> { + pub(crate) fn new(close_token: &'t JsSyntaxToken) -> Self { + Self { close_token } + } + + /// It extracts the formatted leading trivia of the token, without writing it in the buffer + pub(crate) fn format_trailing_trivia(&self) -> impl Format + 't { + format_trailing_trivia(self.close_token) + } + + /// It extracts the formatted trailing trivia of the token, without writing it in the buffer + pub(crate) fn format_leading_trivia(&self) -> impl Format + 't { + format_with(|f| { + let mut buffer = PreambleBuffer::new(f, soft_line_break()); + + write!(buffer, [format_leading_trivia(self.close_token,)]) + }) + } + + /// It extracts the formatted token, without writing it in the buffer + pub(crate) fn format_token(&self) -> impl Format + 't { + format_with(|f| { + f.state_mut().track_token(self.close_token); + write!(f, [format_trimmed_token(self.close_token)]) + }) + } +} diff --git a/crates/rome_js_formatter/src/js/expressions/call_arguments.rs b/crates/rome_js_formatter/src/js/expressions/call_arguments.rs index 3c814dce3b8..a6bb65bbed4 100644 --- a/crates/rome_js_formatter/src/js/expressions/call_arguments.rs +++ b/crates/rome_js_formatter/src/js/expressions/call_arguments.rs @@ -1,10 +1,14 @@ +use crate::builders::{format_close_delimiter, format_open_delimiter}; use crate::prelude::*; -use crate::utils::{is_simple_expression, token_has_comments}; +use crate::utils::{is_call_like_expression, write_arguments_multi_line}; use crate::FormatNodeFields; -use rome_formatter::write; -use rome_js_syntax::JsCallArgumentsFields; -use rome_js_syntax::{JsAnyCallArgument, JsCallArguments}; -use rome_rowan::{AstSeparatedList, SyntaxResult}; +use rome_formatter::{format_args, write}; +use rome_js_syntax::{ + JsAnyCallArgument, JsAnyExpression, JsAnyFunctionBody, JsAnyStatement, JsArrayExpression, + JsArrowFunctionExpression, JsCallArgumentList, JsCallArguments, JsCallArgumentsFields, + JsLanguage, JsSyntaxKind, TsReferenceType, +}; +use rome_rowan::{AstSeparatedElement, AstSeparatedList, SyntaxResult}; impl FormatNodeFields for FormatNodeRule { fn fmt_fields(node: &JsCallArguments, f: &mut JsFormatter) -> FormatResult<()> { @@ -14,60 +18,416 @@ impl FormatNodeFields for FormatNodeRule { r_paren_token, } = node.as_fields(); - if is_simple_function_arguments(node)? { - return write![ + let l_paren_token = l_paren_token?; + let r_paren_token = r_paren_token?; + + if args.len() == 0 { + return write!( f, [ l_paren_token.format(), - group_elements(&args.format()), - r_paren_token.format(), + args.format(), + r_paren_token.format() ] - ]; + ); } - write!( - f, - [ - format_delimited(&l_paren_token?, &args.format(), &r_paren_token?,) - .soft_block_indent() - ] - ) - } -} + // particular formatting for hooks + if let Some((first_argument, second_argument)) = is_react_hook_with_deps_array(&args)? { + write!( + f, + [ + l_paren_token.format(), + first_argument.node().format(), + first_argument.trailing_separator().format(), + space_token(), + second_argument.node().format(), + ] + )?; -/// Returns true if the passed [JsCallArguments] has a single argument -/// that is a simple function expression, array expression or object expression -fn is_simple_function_arguments(node: &JsCallArguments) -> SyntaxResult { - let JsCallArgumentsFields { - l_paren_token, - args, - r_paren_token, - } = node.as_fields(); + // we don't want to print the trailing separator, so if it's present, we remove it + if let Some(separator) = second_argument.trailing_separator()? { + write!(f, [format_removed(separator)])?; + } - if token_has_comments(&l_paren_token?) || token_has_comments(&r_paren_token?) { - return Ok(false); + return write!(f, [r_paren_token.format()]); + } + + // we create open a close delimiters + let open_delimiter = format_open_delimiter(&l_paren_token); + let close_delimiter = format_close_delimiter(&r_paren_token); + + // we now extracts the formatted version of trivias and tokens of the delimiters + // tokens on the left + let l_leading_trivia = open_delimiter.format_leading_trivia(); + let l_paren = open_delimiter.format_token(); + let l_trailing_trivia = open_delimiter.format_trailing_trivia(); + + // tokens on the right + let r_leading_trivia = close_delimiter.format_leading_trivia(); + let r_paren = close_delimiter.format_token(); + let r_trailing_trivia = close_delimiter.format_trailing_trivia(); + + let should_group_first_argument = should_group_first_argument(&args)?; + let should_group_last_argument = should_group_last_argument(&args)?; + + // if the first or last groups needs grouping, then we prepare some special formatting + if should_group_first_argument || should_group_last_argument { + // We finished the "simple cases", we now need to use `best_fitting`. + // We now need to allocate a new vector with cached nodes, this is needed because + // we can't attempt to print the same node twice without incur in "printed token twice" errors. + // We also disallow the trailing separator, we are interested in doing it manually. + let separated: Vec<_> = args + .format_separated(JsSyntaxKind::COMMA) + .with_options( + FormatSeparatedOptions::default() + .with_trailing_separator(TrailingSeparator::Omit), + ) + .map(|e| e.memoized()) + .collect(); + + // We now cache them the delimiters tokens. This is needed because `[rome_formatter::best_fitting]` will try to + // print each version first + // tokens on the left + let l_leading_trivia = l_leading_trivia.memoized(); + let l_paren = l_paren.memoized(); + let l_trailing_trivia = l_trailing_trivia.memoized(); + + // tokens on the right + let r_leading_trivia = r_leading_trivia.memoized(); + let r_paren = r_paren.memoized(); + let r_trailing_trivia = r_trailing_trivia.memoized(); + + let edge_arguments_do_not_break = format_with(|f| { + // `should_group_first_argument` and `should_group_last_argument` are mutually exclusive + // which means that if one is `false`, then the other is `true`. + // This means that in this branch we format the case where `should_group_first_argument`, + // in the else branch we format the case where `should_group_last_argument` is `true`. + + write!(f, [l_leading_trivia, l_paren, l_trailing_trivia,])?; + if should_group_first_argument { + // special formatting of the first element + let mut iter = separated.iter(); + // SAFETY: check on the existence of at least one argument are done before + let first = iter.next().unwrap(); + f.join_with(&space_token()) + .entry(&format_with(|f| { + write!(f, [&format_args![first, expand_parent()]]) + })) + .entries(iter) + .finish()?; + } else { + // special formatting of the last element + let mut iter = separated.iter(); + // SAFETY: check on the existence of at least one argument are done before + let last = iter.next_back().unwrap(); + + f.join_with(&space_token()) + .entries(iter) + .entry(&format_with(|f| { + write!(f, [&format_args![last, expand_parent()]]) + })) + .finish()?; + } + + write!(f, [r_leading_trivia, r_paren, r_trailing_trivia]) + }); + + // This is the version of where all the arguments are broken out + let all_arguments_expanded = format_with(|f| { + // this formatting structure replicates what we have inside the `format_delimited` + // function, but here we use a different way to print the trailing separator + write!( + f, + [ + &l_leading_trivia, + &l_paren, + &group_elements(&format_with(|f| { + write!( + f, + [ + &soft_block_indent(&format_args![ + &l_trailing_trivia, + format_with(|f| { + write_arguments_multi_line(separated.iter(), f) + }), + &r_leading_trivia, + soft_line_break() + ]), + &r_paren + ] + ) + })), + &r_trailing_trivia + ] + ) + }); + + write!( + f, + [best_fitting![ + format_args![ + l_leading_trivia, + l_paren, + l_trailing_trivia, + group_elements(&format_args![format_with(|f| { + write_arguments_multi_line(separated.iter(), f) + })]), + r_leading_trivia, + r_paren, + r_trailing_trivia + ], + edge_arguments_do_not_break, + all_arguments_expanded + ]] + ) + } else { + write!( + f, + [ + l_leading_trivia, + &group_elements(&format_args![ + l_paren, + l_trailing_trivia, + &soft_block_indent(&format_with(|f| { + let separated = + args.format_separated(JsSyntaxKind::COMMA).with_options( + FormatSeparatedOptions::default() + .with_trailing_separator(TrailingSeparator::Omit), + ); + write_arguments_multi_line(separated, f) + }),), + r_leading_trivia, + r_paren, + ],), + r_trailing_trivia + ] + ) + } } +} - if args.len() > 1 { +/// Checks if the the first argument requires grouping +fn should_group_first_argument(list: &JsCallArgumentList) -> SyntaxResult { + if list.len() != 2 { return Ok(false); } + let mut iter = list.iter(); + // SAFETY: checked at the beginning of the function + let first = iter.next().unwrap()?; + let second = iter.next().unwrap()?; - for item in args.elements() { - if let Some(separator) = item.trailing_separator()? { - if token_has_comments(separator) { - return Ok(false); + let has_comments = first.syntax().has_comments_direct(); + + let is_function_like = if let JsAnyCallArgument::JsAnyExpression(expression) = first { + match expression { + JsAnyExpression::JsFunctionExpression(_) => true, + JsAnyExpression::JsArrowFunctionExpression(arrow) => { + matches!(arrow.body()?, JsAnyFunctionBody::JsFunctionBody(_)) } + _ => false, } + } else { + false + }; + + let second_arg_is_function_like = matches!( + second, + JsAnyCallArgument::JsAnyExpression( + JsAnyExpression::JsFunctionExpression(_) + | JsAnyExpression::JsArrowFunctionExpression(_) + | JsAnyExpression::JsConditionalExpression(_) + ) + ); + Ok(!has_comments + && is_function_like + && !second_arg_is_function_like + && !could_group_argument(&second, false)?) +} + +/// Checks if the last group requires grouping +fn should_group_last_argument(list: &JsCallArgumentList) -> SyntaxResult { + let mut iter = list.iter().rev(); + let last = iter.next(); + let penultimate = iter.next(); + + if let Some(last) = last { + let last = last?; + let check_with_penultimate = if let Some(penultimate) = penultimate { + let penultimate = penultimate?; + (last.syntax().kind() != penultimate.syntax().kind()) + && !JsArrayExpression::can_cast(penultimate.syntax().kind()) + || !JsArrowFunctionExpression::can_cast(last.syntax().kind()) + } else { + true + }; + + Ok(!last.syntax().has_comments_direct() + && could_group_argument(&last, false)? + && check_with_penultimate) + } else { + Ok(false) + } +} + +/// Checks if the current argument could be grouped +fn could_group_argument( + argument: &JsAnyCallArgument, + is_arrow_recursion: bool, +) -> SyntaxResult { + let result = if let JsAnyCallArgument::JsAnyExpression(argument) = argument { + match argument { + JsAnyExpression::JsObjectExpression(object_expression) => { + object_expression.members().len() > 0 + || object_expression + .syntax() + .first_or_last_token_have_comments() + } + + JsAnyExpression::JsArrayExpression(array_expression) => { + array_expression.elements().len() > 0 + || array_expression + .syntax() + .first_or_last_token_have_comments() + } + JsAnyExpression::TsTypeAssertionExpression(assertion_expression) => { + could_group_argument( + &JsAnyCallArgument::JsAnyExpression(assertion_expression.expression()?), + false, + )? + } + + JsAnyExpression::TsAsExpression(as_expression) => could_group_argument( + &JsAnyCallArgument::JsAnyExpression(as_expression.expression()?), + false, + )?, + JsAnyExpression::JsArrowFunctionExpression(arrow_function) => { + let body = arrow_function.body()?; + let return_type_annotation = arrow_function.return_type_annotation(); + + // Handles cases like: + // + // app.get("/", (req, res): void => { + // res.send("Hello World!"); + // }); + // + // export class Thing implements OtherThing { + // do: (type: Type) => Provider = memoize( + // (type: ObjectType): Provider => {} + // ); + // } + let can_group_type = !return_type_annotation.and_then(|rty| rty.ty().ok()).map_or( + false, + |any_type| { + TsReferenceType::can_cast(any_type.syntax().kind()) + || if let JsAnyFunctionBody::JsFunctionBody(function_body) = &body { + function_body + .statements() + .iter() + .any(|st| matches!(st, JsAnyStatement::JsEmptyStatement(_))) + } else { + true + } + }, + ); - match item.node() { - Ok(JsAnyCallArgument::JsAnyExpression(expr)) => { - if !is_simple_expression(expr)? { - return Ok(false); + let body_is_delimited = matches!( + body, + JsAnyFunctionBody::JsFunctionBody(_) + | JsAnyFunctionBody::JsAnyExpression(JsAnyExpression::JsObjectExpression( + _ + )) + | JsAnyFunctionBody::JsAnyExpression(JsAnyExpression::JsArrayExpression(_)) + ); + + if let JsAnyFunctionBody::JsAnyExpression(any_expression) = body.clone() { + let is_nested_arrow_function = + if let JsAnyExpression::JsArrowFunctionExpression( + arrow_function_expression, + ) = &any_expression + { + arrow_function_expression + .body() + .ok() + .and_then(|body| body.as_js_any_expression().cloned()) + .and_then(|body| { + could_group_argument( + &JsAnyCallArgument::JsAnyExpression(body), + true, + ) + .ok() + }) + .unwrap_or(false) + } else { + false + }; + + body_is_delimited + && is_nested_arrow_function + && can_group_type + && (!is_arrow_recursion + && (is_call_like_expression(&any_expression) + || matches!( + body, + JsAnyFunctionBody::JsAnyExpression( + JsAnyExpression::JsConditionalExpression(_) + ) + ))) + } else { + body_is_delimited && can_group_type } } - _ => return Ok(false), + + JsAnyExpression::JsFunctionExpression(_) => true, + _ => false, } - } + } else { + false + }; + + Ok(result) +} + +type HookArgs = ( + AstSeparatedElement, + AstSeparatedElement, +); +/// This function is used to check if the code is a hook-like code: +/// +/// ```js +/// useMemo(() => {}, []) +/// ``` +fn is_react_hook_with_deps_array(node: &JsCallArgumentList) -> SyntaxResult> { + let result = if node.len() == 2 { + let mut iter = node.elements(); + let first_element = iter.next().unwrap(); + let second_element = iter.next().unwrap(); + // SAFETY: covered by the previous if check + let first_node = first_element.node()?; + let second_node = second_element.node()?; + let first_node_matches = if let JsAnyCallArgument::JsAnyExpression( + JsAnyExpression::JsArrowFunctionExpression(arrow_function), + ) = first_node + { + let no_parameters = arrow_function.parameters()?.is_empty(); + let body = arrow_function.body()?; + let is_block = matches!(body, JsAnyFunctionBody::JsFunctionBody(_)); + + no_parameters && is_block + } else { + false + }; + + let second_node_matches = matches!(second_node, JsAnyCallArgument::JsAnyExpression(_)); + let no_comments = !node.syntax().first_or_last_token_have_comments(); + if first_node_matches && second_node_matches && no_comments { + Some((first_element, second_element)) + } else { + None + } + } else { + None + }; - Ok(true) + Ok(result) } diff --git a/crates/rome_js_formatter/src/js/expressions/object_expression.rs b/crates/rome_js_formatter/src/js/expressions/object_expression.rs index 505973857a0..b11abf12eae 100644 --- a/crates/rome_js_formatter/src/js/expressions/object_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/object_expression.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::has_leading_newline; +use crate::utils::node_has_leading_newline; use crate::FormatNodeFields; use rome_formatter::write; use rome_js_syntax::JsObjectExpression; @@ -13,7 +13,7 @@ impl FormatNodeFields for FormatNodeRule r_curly_token, } = node.as_fields(); - let has_newline = has_leading_newline(members.syntax()); + let has_newline = node_has_leading_newline(members.syntax()); if members.is_empty() { write!( diff --git a/crates/rome_js_formatter/src/js/lists/call_argument_list.rs b/crates/rome_js_formatter/src/js/lists/call_argument_list.rs index 31c14a900d2..718cf211855 100644 --- a/crates/rome_js_formatter/src/js/lists/call_argument_list.rs +++ b/crates/rome_js_formatter/src/js/lists/call_argument_list.rs @@ -1,13 +1,26 @@ use crate::generated::FormatJsCallArgumentList; use crate::prelude::*; +use crate::utils::write_arguments_multi_line; +use rome_formatter::write; use rome_js_syntax::{JsCallArgumentList, JsSyntaxKind}; impl FormatRule for FormatJsCallArgumentList { type Context = JsFormatContext; fn fmt(node: &JsCallArgumentList, f: &mut JsFormatter) -> FormatResult<()> { - f.join_with(&soft_line_break_or_space()) - .entries(node.format_separated(JsSyntaxKind::COMMA)) - .finish() + if node.len() == 0 { + return Ok(()); + } + + write!( + f, + [&group_elements(&soft_block_indent(&format_with(|f| { + let separated = node.format_separated(JsSyntaxKind::COMMA).with_options( + FormatSeparatedOptions::default() + .with_trailing_separator(TrailingSeparator::Omit), + ); + write_arguments_multi_line(separated, f) + })))] + ) } } diff --git a/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs b/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs index 0aae763c557..d919c260fa2 100644 --- a/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::{has_leading_newline, FormatWithSemicolon}; +use crate::utils::{node_has_leading_newline, FormatWithSemicolon}; use rome_formatter::write; use crate::FormatNodeFields; @@ -25,7 +25,7 @@ impl FormatNodeFields for FormatNodeRule { + res.send("Hello World!"); + }); + + export class Thing implements OtherThing { + do: (type: Type) => Provider = memoize( + (type: ObjectType): Provider => {} + ); + } + +"#; + // let src = r#"useEffect(() => { hey; }, [1, 4])"#; + + let syntax = SourceType::tsx(); let tree = parse(src, 0, syntax); let result = format_node(JsFormatContext::default(), &tree.syntax()) .unwrap() diff --git a/crates/rome_js_formatter/src/separated.rs b/crates/rome_js_formatter/src/separated.rs index e12309dc0bf..b8de05eed04 100644 --- a/crates/rome_js_formatter/src/separated.rs +++ b/crates/rome_js_formatter/src/separated.rs @@ -47,6 +47,9 @@ where // A trailing separator was present where it wasn't allowed, opt out of formatting return Err(FormatError::SyntaxError); } + TrailingSeparator::Omit => { + write!(f, [format_removed(separator)])?; + } } } else { write!(f, [separator.format()])?; @@ -63,7 +66,7 @@ where TrailingSeparator::Mandatory => { format_inserted(self.separator).fmt(f)?; } - TrailingSeparator::Disallowed => { /* no op */ } + TrailingSeparator::Omit | TrailingSeparator::Disallowed => { /* no op */ } } } else { unreachable!( @@ -169,6 +172,10 @@ pub enum TrailingSeparator { /// A trailing separator is mandatory for the syntax to be correct Mandatory, + + /// A trailing separator might be present, but the consumer + /// decides to remove it + Omit, } impl Default for TrailingSeparator { diff --git a/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs b/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs index 287634046fd..d3c02e53f38 100644 --- a/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs @@ -1,13 +1,13 @@ use crate::generated::FormatTsEnumMemberList; use crate::prelude::*; -use crate::utils::has_leading_newline; +use crate::utils::node_has_leading_newline; use rome_js_syntax::{JsSyntaxKind, TsEnumMemberList}; impl FormatRule for FormatTsEnumMemberList { type Context = JsFormatContext; fn fmt(node: &TsEnumMemberList, f: &mut JsFormatter) -> FormatResult<()> { - let has_newline = has_leading_newline(node.syntax()); + let has_newline = node_has_leading_newline(node.syntax()); f.join_with(&if has_newline { hard_line_break() diff --git a/crates/rome_js_formatter/src/ts/types/object_type.rs b/crates/rome_js_formatter/src/ts/types/object_type.rs index c7a09f8c8e1..2c5ac9b7ab6 100644 --- a/crates/rome_js_formatter/src/ts/types/object_type.rs +++ b/crates/rome_js_formatter/src/ts/types/object_type.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::has_leading_newline; +use crate::utils::node_has_leading_newline; use crate::FormatNodeFields; use rome_formatter::write; use rome_js_syntax::{TsObjectType, TsObjectTypeFields}; @@ -12,7 +12,7 @@ impl FormatNodeFields for FormatNodeRule { r_curly_token, } = node.as_fields(); - if has_leading_newline(members.syntax()) { + if node_has_leading_newline(members.syntax()) { write!( f, [ diff --git a/crates/rome_js_formatter/src/utils/mod.rs b/crates/rome_js_formatter/src/utils/mod.rs index 594c1645ff6..04bea9d6a36 100644 --- a/crates/rome_js_formatter/src/utils/mod.rs +++ b/crates/rome_js_formatter/src/utils/mod.rs @@ -17,7 +17,7 @@ pub(crate) use object::{ is_break_after_colon, property_object_member_layout, write_member_name, PropertyObjectMemberLayout, }; -use rome_formatter::{normalize_newlines, write, Buffer, VecBuffer}; +use rome_formatter::{format_args, normalize_newlines, write, Buffer, VecBuffer}; use rome_js_syntax::suppression::{has_suppressions_category, SuppressionCategory}; use rome_js_syntax::JsSyntaxKind::JS_STRING_LITERAL; use rome_js_syntax::{ @@ -27,6 +27,7 @@ use rome_js_syntax::{ }; use rome_js_syntax::{JsSyntaxKind, JsSyntaxNode, JsSyntaxToken}; use rome_rowan::{AstNode, AstNodeList, Direction, SyntaxResult}; +use std::fmt::Debug; pub(crate) use simple::*; pub(crate) use string_utils::*; @@ -137,7 +138,7 @@ pub(crate) fn has_formatter_trivia(node: &JsSyntaxNode) -> bool { } /// Returns true if this node contains newlines in trivias. -pub(crate) fn has_leading_newline(node: &JsSyntaxNode) -> bool { +pub(crate) fn node_has_leading_newline(node: &JsSyntaxNode) -> bool { if let Some(leading_trivia) = node.first_leading_trivia() { for piece in leading_trivia.pieces() { if piece.is_newline() { @@ -523,3 +524,27 @@ impl Format for FormatMemberName { } } } + +/// This function is in charge to format the call arguments. +pub(crate) fn write_arguments_multi_line, I>( + separated: I, + f: &mut JsFormatter, +) -> FormatResult<()> +where + I: Iterator, +{ + let mut iterator = separated.peekable(); + let mut join_with = f.join_with(soft_line_break_or_space()); + + while let Some(element) = iterator.by_ref().next() { + let last = iterator.peek().is_none(); + + if last { + join_with.entry(&format_args![&element, &if_group_breaks(&token(","))]); + } else { + join_with.entry(&element); + } + } + + join_with.finish() +} diff --git a/crates/rome_js_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap b/crates/rome_js_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap index cf5c162de4c..5a6371d92a9 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/arrow/arrow_nested.js.snap @@ -44,13 +44,10 @@ Seq(typeDef.interface.groups).forEach( (group) => Seq(group.members).forEach( (member, memberName) => - markdownDoc( - member.doc, - { - typePath: typePath.concat(memberName.slice(1)), - signatures: member.signatures, - }, - ), + markdownDoc(member.doc, { + typePath: typePath.concat(memberName.slice(1)), + signatures: member.signatures, + }), ), ); @@ -62,16 +59,15 @@ const promiseFromCallback = (fn) => return reject(err); } return resolve(result); - },), + }), ); -runtimeAgent.getProperties( - objectId, - false, // ownProperties - false, // accessorPropertiesOnly - false, // generatePreview - (error, properties, internalProperties) => { - return 1; - }, -); +runtimeAgent.getProperties(objectId, false, false, false, ( + // ownProperties // accessorPropertiesOnly // generatePreview + error, + properties, + internalProperties, +) => { + return 1; +}); diff --git a/crates/rome_js_formatter/tests/specs/js/module/arrow/call.js.snap b/crates/rome_js_formatter/tests/specs/js/module/arrow/call.js.snap index 13c6570bd65..d25aab91e36 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/arrow/call.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/arrow/call.js.snap @@ -61,14 +61,11 @@ const testResults = results.testResults.map( (testResult) => formatResult(testResult, formatter, reporter), ); -it( - "mocks regexp instances", - () => { - expect( - // () => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/)), - ).not.toThrow(); - }, -); +it("mocks regexp instances", () => { + expect( + // () => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/)), + ).not.toThrow(); +}); expect(() => asyncRequest({ url: "/test-endpoint" })); // .toThrowError(/Required parameter/); @@ -116,5 +113,5 @@ romise.then( ## Lines exceeding width of 80 characters - 54: result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail", + 51: result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail", diff --git a/crates/rome_js_formatter/tests/specs/js/module/arrow/params.js.snap b/crates/rome_js_formatter/tests/specs/js/module/arrow/params.js.snap index e6a0a5c0f9f..9720d5d8eb1 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/arrow/params.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/arrow/params.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: params.js --- # Input @@ -367,21 +368,19 @@ foo(([{ a: { b: { c: { d, e } } } }]) => {}); foo(([...{ a: { b: { c: { d, e } } } }]) => {}); -foo( - ( - n = { - a: { - b: { - c: { - d, - - e, - }, +foo(( + n = { + a: { + b: { + c: { + d, + + e, }, }, }, - ) => {}, -); + }, +) => {}); foo(({ x: [{ a, b }] }) => {}); @@ -407,39 +406,33 @@ foo((...[{ a, b }]) => {}); foo(([...[{ a, b }]]) => {}); -foo( - ( - a = [ - { - a, +foo(( + a = [ + { + a, - b, - }, - ], - ) => {}, -); + b, + }, + ], +) => {}); foo((a = (({ a, b }) => {})()) => {}); -foo( - ( - a = f({ - a, +foo(( + a = f({ + a, - b, - },), - ) => {}, -); + b, + }), +) => {}); foo((a = ({ a, b }) => {}) => {}); -foo( - ( - a = 1 + f({ - a, +foo(( + a = 1 + f({ + a, - b, - },), - ) => {}, -); + b, + }), +) => {}); diff --git a/crates/rome_js_formatter/tests/specs/js/module/call_expression.js b/crates/rome_js_formatter/tests/specs/js/module/call_expression.js new file mode 100644 index 00000000000..80ae11d0e8b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/call_expression.js @@ -0,0 +1,40 @@ + +useEffect(() => { + +}, [a, b]) + +useMemo(() => { + return { + d, e + } +}, [a, b]) + +useMemo(() => { + + } // some comment + , + [a, b] +) + +test.expect(t => { + t.true(a) +}) + +test.expect(t => { + t.true(a) +}, false) + +test.something(t => { + t.true() +}, context => { + context.flush() +}) + +// trailing separator omitted +test.expect(t => { + t.true(a) +}, false,) + +test.expect(t => { + t.true(a) +}, false, /* something */) \ No newline at end of file diff --git a/crates/rome_js_formatter/tests/specs/js/module/call_expression.js.snap b/crates/rome_js_formatter/tests/specs/js/module/call_expression.js.snap new file mode 100644 index 00000000000..63eb33ad4a1 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/call_expression.js.snap @@ -0,0 +1,91 @@ +--- +source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 +expression: call_expression.js +--- +# Input + +useEffect(() => { + +}, [a, b]) + +useMemo(() => { + return { + d, e + } +}, [a, b]) + +useMemo(() => { + + } // some comment + , + [a, b] +) + +test.expect(t => { + t.true(a) +}) + +test.expect(t => { + t.true(a) +}, false) + +test.something(t => { + t.true() +}, context => { + context.flush() +}) + +// trailing separator omitted +test.expect(t => { + t.true(a) +}, false,) + +test.expect(t => { + t.true(a) +}, false, /* something */) +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +----- +useEffect(() => {}, [a, b]); + +useMemo(() => { + return { + d, + e, + }; +}, [a, b]); + +useMemo(() => {}, [a, b]); // some comment + +test.expect((t) => { + t.true(a); +}); + +test.expect((t) => { + t.true(a); +}, false); + +test.something( + (t) => { + t.true(); + }, + (context) => { + context.flush(); + }, +); + +// trailing separator omitted +test.expect((t) => { + t.true(a); +}, false); + +test.expect((t) => { + t.true(a); +}, false /* something */); + diff --git a/crates/rome_js_formatter/tests/specs/js/module/comments.js.snap b/crates/rome_js_formatter/tests/specs/js/module/comments.js.snap index 2e15076a728..74e0e98b62e 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/comments.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/comments.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: comments.js --- # Input @@ -97,15 +98,13 @@ import { expression(/* block comment */); expression( - /* block comment */ +/* block comment */ ); -expression( - // line comment -); +expression(); // line comment expression( - // line comment +// line comment ); expression( diff --git a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap index f029b3e708e..8b38e84fb74 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: computed.js --- # Input @@ -19,10 +20,7 @@ Quote style: Double Quotes ----- nock(/test/) .matchHeader("Accept", "application/json")[httpMethodNock(method)]("/foo") - .reply( - 200, - { - foo: "bar", - }, - ); + .reply(200, { + foo: "bar", + }); diff --git a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap index 63e138938cb..05259d257eb 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: inline-merge.js --- # Input @@ -31,8 +32,8 @@ _.flatMap(this.visibilityHandlers, (fn) => fn()) Object.keys( availableLocales({ test: true, - },), + }), ).forEach((locale) => { // ... -},); +}); diff --git a/crates/rome_js_formatter/tests/specs/js/module/function/function.js.snap b/crates/rome_js_formatter/tests/specs/js/module/function/function.js.snap index efd7cfd1779..d7cb070eb9f 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/function/function.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/function/function.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: function.js --- # Input @@ -66,7 +67,7 @@ function foo() { useEffect(() => { setRef(); - },); + }); return ref; } diff --git a/crates/rome_js_formatter/tests/specs/js/module/object/property_object_member.js.snap b/crates/rome_js_formatter/tests/specs/js/module/object/property_object_member.js.snap index 46667b7563b..d94be9d4026 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/object/property_object_member.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/object/property_object_member.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: property_object_member.js --- # Input @@ -218,12 +219,12 @@ const fluidObject = { created: "09/01/2017 17:25", }, ], - render: withGraphQLQuery( - "node(1234567890){image{uri}}", - function (container, data) { - return "image"; - }, - ), + render: withGraphQLQuery("node(1234567890){image{uri}}", function ( + container, + data, + ) { + return "image"; + }), loadNext: (stateIsOK && hasNext) || { skipNext: true, }, diff --git a/crates/rome_js_formatter/tests/specs/js/module/statement/if_else.js.snap b/crates/rome_js_formatter/tests/specs/js/module/statement/if_else.js.snap index 0e8f34c4238..dc0ecb630c0 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/statement/if_else.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/statement/if_else.js.snap @@ -1,8 +1,7 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs -assertion_line: 242 +assertion_line: 257 expression: if_else.js - --- # Input if(a); @@ -125,6 +124,7 @@ if (true) { if (true) { // trailing + } else { // trailing } diff --git a/crates/rome_js_formatter/tests/specs/jsx/attributes.jsx.snap b/crates/rome_js_formatter/tests/specs/jsx/attributes.jsx.snap index 6b58cd3ea2d..acbc729b24d 100644 --- a/crates/rome_js_formatter/tests/specs/jsx/attributes.jsx.snap +++ b/crates/rome_js_formatter/tests/specs/jsx/attributes.jsx.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 expression: attributes.jsx --- # Input @@ -71,16 +72,13 @@ Quote style: Double Quotes />; formatResult(testResult, formatter, reporter), ); -it( - "mocks regexp instances", - () => { - expect( - () => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/)), - ).not.toThrow(); - }, -); +it("mocks regexp instances", () => { + expect( + () => moduleMocker.generateFromMetadata(moduleMocker.getMetadata(/a/)), + ).not.toThrow(); +}); expect(() => asyncRequest({ url: "/test-endpoint" })).toThrowError( /Required parameter/, @@ -106,6 +104,6 @@ promise.then( # Lines exceeding max width of 80 characters ``` - 52: result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail", + 49: result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail", ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/assignment/call-with-template.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/assignment/call-with-template.js.snap index 14befb74650..d659544eb15 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/assignment/call-with-template.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/assignment/call-with-template.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: call-with-template.js --- # Input @@ -25,11 +26,11 @@ const result = template( `, )({ SOME_VAR: value, -},); +}); const output = template(`function f() %%A%%`)({ A: t.blockStatement([]), -},); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/assignment/issue-6922.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/assignment/issue-6922.js.snap index 1963aa1488b..31d488638c2 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/assignment/issue-6922.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/assignment/issue-6922.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: issue-6922.js --- # Input @@ -44,10 +45,9 @@ async function f() { return { data, status }; } -const data1 = request.delete( - "----------------------------------------------", - { validateStatus: () => true }, -); +const data1 = request.delete("----------------------------------------------", { + validateStatus: () => true, +}); const data2 = request.delete( "----------------------------------------------x", diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/assignment/lone-arg.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/assignment/lone-arg.js.snap index a39c032c38b..102f6546bb2 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/assignment/lone-arg.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/assignment/lone-arg.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: lone-arg.js --- # Input @@ -33,7 +34,7 @@ let vgChannel = pointPositionDefaultRef({ model, defaultPos, channel, -},)(); +})(); let vgChannel2 = pointPositionDefaultRef({ model, defaultPos, channel })(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/short-right.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/short-right.js.snap index 32acb9aec41..79e53cfe781 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/short-right.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/binary-expressions/short-right.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: short-right.js --- # Input @@ -44,7 +45,7 @@ const isPartOfPackageJSON = dependenciesArray.indexOf( defaultContent.filter((defaultLocale) => { // ... -},)[0] || null; +})[0] || null; ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/break.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/break.js.snap index 4f63097794e..bd172cf0d4b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/break.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/break.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: break.js --- # Input @@ -56,26 +57,24 @@ h( f( g(() => { a; - },), + }), ), ); -deepCopyAndAsyncMapLeavesA( - { source: sourceValue, destination: destination[sourceKey] }, - { valueMapper, overwriteExistingKeys }, -); +deepCopyAndAsyncMapLeavesA({ + source: sourceValue, + destination: destination[sourceKey], +}, { valueMapper, overwriteExistingKeys }); -deepCopyAndAsyncMapLeavesB( - 1337, - { source: sourceValue, destination: destination[sourceKey] }, - { valueMapper, overwriteExistingKeys }, -); +deepCopyAndAsyncMapLeavesB(1337, { + source: sourceValue, + destination: destination[sourceKey], +}, { valueMapper, overwriteExistingKeys }); -deepCopyAndAsyncMapLeavesC( - { source: sourceValue, destination: destination[sourceKey] }, - 1337, - { valueMapper, overwriteExistingKeys }, -); +deepCopyAndAsyncMapLeavesC({ + source: sourceValue, + destination: destination[sourceKey], +}, 1337, { valueMapper, overwriteExistingKeys }); function someFunction(url) { return get(url).then( @@ -93,12 +92,12 @@ expect( new LongLongLongLongLongRange([0, 0], [0, 0]), ).toEqualAtomLongLongLongLongRange(new LongLongLongRange([0, 0], [0, 0])); -["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce( - (allColors, color) => { - return allColors.concat(color); - }, - [], -); +["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(( + allColors, + color, +) => { + return allColors.concat(color); +}, []); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/parent.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/parent.js.snap index 84acd94f2d0..d504cd97ca7 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/parent.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/parent.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: parent.js --- # Input @@ -18,15 +19,14 @@ runtimeAgent.getProperties( # Output ```js -runtimeAgent.getProperties( - objectId, - false, // ownProperties - false, // accessorPropertiesOnly - false, // generatePreview - (error, properties, internalProperties) => { - return 1; - }, -); +runtimeAgent.getProperties(objectId, false, false, false, ( + // ownProperties // accessorPropertiesOnly // generatePreview + error, + properties, + internalProperties, +) => { + return 1; +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/react.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/react.js.snap index 3545b0b627b..db948133c5a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/react.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/react.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: react.js --- # Input @@ -74,117 +75,108 @@ function Comp5() { # Output ```js function helloWorld() { - useEffect( - () => { - // do something - }, - [props.value], - ); - useEffect( - () => { - // do something - }, - [ - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - ], - ); + useEffect(() => { + // do something + }, [props.value]); + useEffect(() => { + // do something + }, [ + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + ]); } function helloWorldWithReact() { - React.useEffect( - () => { - // do something - }, - [props.value], - ); - React.useEffect( - () => { - // do something - }, - [ - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - ], - ); + React.useEffect(() => { + // do something + }, [props.value]); + React.useEffect(() => { + // do something + }, [ + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + ]); } function MyComponent(props) { - useEffect( - () => { - console.log("some code", props.foo); - }, - // We need to disable the eslint warning here, - // because of some complicated reason. - // eslint-disable line react-hooks/exhaustive-deps - [], - ); + useEffect(() => { + console.log("some code", props.foo); + }, + // We need to disable the eslint warning here, + // because of some complicated reason. + // eslint-disable line react-hooks/exhaustive-deps + []); return null; } function Comp1() { - const { firstName, lastName } = useMemo( - () => parseFullName(fullName), - [fullName], - ); + const { firstName, lastName } = useMemo(() => parseFullName(fullName), [ + fullName, + ]); } function Comp2() { - const { firstName, lastName } = useMemo( - () => func(), - [ - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - props.value, - ], - ); + const { firstName, lastName } = useMemo(() => func(), [ + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + props.value, + ]); } function Comp3() { - const { firstName, lastName } = useMemo( - (aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii, jjj, kkk) => - func(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii, jjj, kkk), - [foo, bar, baz], - ); + const { firstName, lastName } = useMemo(( + aaa, + bbb, + ccc, + ddd, + eee, + fff, + ggg, + hhh, + iii, + jjj, + kkk, + ) => func(aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii, jjj, kkk), [ + foo, + bar, + baz, + ]); } function Comp4() { - const { firstName, lastName } = useMemo( - () => - (foo && bar && baz) || - baz || - (foo && baz(foo) + bar(foo) + foo && bar && baz) || - baz || - (foo && baz(foo) + bar(foo)), - [foo, bar, baz], - ); + const { firstName, lastName } = useMemo(() => + (foo && bar && baz) || + baz || + (foo && baz(foo) + bar(foo) + foo && bar && baz) || + baz || + (foo && baz(foo) + bar(foo)), [foo, bar, baz]); } function Comp5() { diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/reduce.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/reduce.js.snap index 5577f5127e8..3cdca9f62ed 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/reduce.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/break-calls/reduce.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: reduce.js --- # Input @@ -18,15 +19,17 @@ const [ first2 ] = array.reduce( # Output ```js -const [first1] = array.reduce( - () => [accumulator, element, accumulator, element], - [fullName], -); +const [first1] = array.reduce(() => [ + accumulator, + element, + accumulator, + element, +], [fullName]); -const [first2] = array.reduce( - (accumulator, element) => [accumulator, element], - [fullName], -); +const [first2] = array.reduce((accumulator, element) => [ + accumulator, + element, +], [fullName]); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/non-casts.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/non-casts.js.snap index 01cf7ca9491..a988a1d708c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/non-casts.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments-closure-typecast/non-casts.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: non-casts.js --- # Input @@ -31,18 +32,18 @@ const w1 = /** @typefoo Foo */ (value); z((x) => { (foo)((bar)(2 + (3))); return (1); -},); +}); /** @type { } */ z((x) => { (foo)((bar)(2 + (3))); return (1); -},); +}); /** @type {number} */ let q = z((x) => { return (1); -},); +}); const w1 = /** @typefoo Foo */ (value); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/arrow.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/arrow.js.snap index 6aefbe7e822..e3959dd29aa 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/arrow.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/arrow.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: arrow.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/call_comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/call_comment.js.snap index 36e6b6315d2..2676bfd9b80 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/call_comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/call_comment.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: call_comment.js --- # Input @@ -23,20 +24,17 @@ render?.( // Warm any cache # Output ```js -render( - // Warm any cache +render( // Warm any cache , container, ); -React.render( - // Warm any cache +React.render( // Warm any cache , container, ); -render?.( - // Warm any cache +render?.( // Warm any cache , container, ); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling.js.snap index 4a875afdfc5..798915cffe5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: dangling.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap index ea6d5e95df7..4c39bf66506 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: dangling_array.js --- # Input @@ -16,7 +17,7 @@ expect(() => {}).toTriggerReadyStateChanges([ ```js expect(() => {}).toTriggerReadyStateChanges([ // Nothing. -],); +]); [1 /* first comment */, 2 /* second comment */, 3]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dynamic_imports.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dynamic_imports.js.snap index 77aedf41d84..ed7b8bc3ef9 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dynamic_imports.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dynamic_imports.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: dynamic_imports.js --- # Input @@ -39,7 +40,7 @@ import("something" /* Hello */ + "else"); import( /* Hello */ "something", - /* Hello */ +/* Hello */ ); wrap(import(/* Hello */ "something")); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/function-declaration.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/function-declaration.js.snap index 052371461e3..a88357459ca 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/function-declaration.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/function-declaration.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: function-declaration.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/issues.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/issues.js.snap index 43a044328c0..8df29ece356 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/issues.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/issues.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: issues.js --- # Input @@ -88,7 +89,7 @@ this.call(a, /* comment */ b); throw new ProcessSystemError({ code: acc.error.code, // Alias of errno originalError: acc.error, // Just in case. -},); +}); // Missing one level of indentation because of the comment const rootEpic = (actions, store) => ( @@ -97,7 +98,7 @@ const rootEpic = (actions, store) => ( .catch((err, stream) => { getLogger().error(err); return stream; - },) + }) ); // optional trailing comma gets moved all the way to the beginning @@ -149,7 +150,7 @@ const result = asyncExecute("non_existing_command", /* args */ []); // The closing paren is printed on the same line as the comment foo( {}, - // Hi +// Hi ); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class-property.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class-property.js.snap index 0736611e4e4..163f9b5df7f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class-property.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/class-property.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: class-property.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/empty_paren_comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/empty_paren_comment.js.snap index e4832492d40..c0d78d2e6fd 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/empty_paren_comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/empty-paren-comment/empty_paren_comment.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: empty_paren_comment.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/first-argument-expansion/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/first-argument-expansion/test.js.snap index fd7e9f15dc2..b00c3cf1d56 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/first-argument-expansion/test.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/first-argument-expansion/test.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: test.js --- # Input @@ -122,75 +123,45 @@ func((args) => { # Output ```js -setTimeout( - function () { - thing(); - }, - 500, -); +setTimeout(function () { + thing(); +}, 500); -["a", "b", "c"].reduce( - function (item, thing) { - return thing + " " + item; - }, - "letters:", -); +["a", "b", "c"].reduce(function (item, thing) { + return thing + " " + item; +}, "letters:"); -func( - () => { - thing(); - }, - identifier, -); +func(() => { + thing(); +}, identifier); -func( - function () { - thing(); - }, - this.props.timeout * 1000, -); +func(function () { + thing(); +}, this.props.timeout * 1000); -func( - (that) => { - thing(); - }, - this.props.getTimeout(), -); +func((that) => { + thing(); +}, this.props.getTimeout()); -func( - () => { - thing(); - }, - true, -); +func(() => { + thing(); +}, true); -func( - () => { - thing(); - }, - null, -); +func(() => { + thing(); +}, null); -func( - () => { - thing(); - }, - undefined, -); +func(() => { + thing(); +}, undefined); -func( - () => { - thing(); - }, - /regex.*?/, -); +func(() => { + thing(); +}, /regex.*?/); -func( - () => { - thing(); - }, - 1 ? 2 : 3, -); +func(() => { + thing(); +}, 1 ? 2 : 3); func( function () { @@ -199,34 +170,25 @@ func( 1 ? 2 : 3, ); -func( - () => { - thing(); - }, - something() ? someOtherThing() : somethingElse(true, 0), -); +func(() => { + thing(); +}, something() ? someOtherThing() : somethingElse(true, 0)); -func( - () => { - thing(); - }, - something( - longArgumentName, - anotherLongArgumentName, - ) ? someOtherThing() : somethingElse(true, 0), -); +func(() => { + thing(); +}, something( + longArgumentName, + anotherLongArgumentName, +) ? someOtherThing() : somethingElse(true, 0)); -func( - () => { - thing(); - }, - something( - longArgumentName, - anotherLongArgumentName, - anotherLongArgumentName, - anotherLongArgumentName, - ) ? someOtherThing() : somethingElse(true, 0), -); +func(() => { + thing(); +}, something( + longArgumentName, + anotherLongArgumentName, + anotherLongArgumentName, + anotherLongArgumentName, +) ? someOtherThing() : somethingElse(true, 0)); compose( (a) => { @@ -235,26 +197,21 @@ compose( (b) => b * b, ); -somthing.reduce( - function (item, thing) { - return thing.blah = item; - }, - {}, -); +somthing.reduce(function (item, thing) { + return thing.blah = item; +}, {}); -somthing.reduce( - function (item, thing) { - return thing.push(item); - }, - [], -); +somthing.reduce(function (item, thing) { + return thing.push(item); +}, []); -reallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongMethod( - (f, g, h) => { - return f.pop(); - }, - true, -); +reallyLongLongLongLongLongLongLongLongLongLongLongLongLongLongMethod(( + f, + g, + h, +) => { + return f.pop(); +}, true); // Don't do the rest of these @@ -266,12 +223,9 @@ func( false, ); -func( - () => { - thing(); - }, - { yes: true, cats: 5 }, -); +func(() => { + thing(); +}, { yes: true, cats: 5 }); compose( (a) => { @@ -302,13 +256,10 @@ setTimeout( 500, ); -setTimeout( - /* blip */ - function () { - thing(); - }, - 500, -); +setTimeout(/* blip */ +function () { + thing(); +}, 500); func( (args) => { diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap index 1d63a77c60b..e38fae452ae 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: function_expression.js --- # Input @@ -34,35 +35,26 @@ db.collection('indexOptionDefault').createIndex({ a: 1 }, { # Output ```js //https://github.com/prettier/prettier/issues/3002 -beep.boop().baz( - "foo", - { - some: { - thing: { - nested: true, - }, +beep.boop().baz("foo", { + some: { + thing: { + nested: true, }, }, - { another: { thing: true } }, - () => {}, -); +}, { another: { thing: true } }, () => {}); //https://github.com/prettier/prettier/issues/2984 -db.collection("indexOptionDefault").createIndex( - { a: 1 }, - { - indexOptionDefaults: true, - w: 2, - wtimeout: 1000, - }, - function (err) { - test.equal(null, err); - test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern); +db.collection("indexOptionDefault").createIndex({ a: 1 }, { + indexOptionDefaults: true, + w: 2, + wtimeout: 1000, +}, function (err) { + test.equal(null, err); + test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern); - client.close(); - done(); - }, -); + client.close(); + done(); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/array.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/array.js.snap index 7e9692509ce..e42a54de330 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/array.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-single-destructuring/array.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: array.js --- # Input @@ -73,20 +74,11 @@ class A { } } -promise.then( - ( - [ - firstResult, - secondResult, - thirdResult, - fourthResult, - fifthResult, - ...rest - ], - ) => { - return rest; - }, -); +promise.then(( + [firstResult, secondResult, thirdResult, fourthResult, fifthResult, ...rest], +) => { + return rest; +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/gobject_connect.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/gobject_connect.js.snap index 1566de90161..56b0257987b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/gobject_connect.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/gobject_connect.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: gobject_connect.js --- # Input @@ -21,13 +22,10 @@ app.connect( # Output ```js button.connect("clicked", () => doSomething()); -app.connect( - "activate", - async () => { - await data.load(); - win.show_all(); - }, -); +app.connect("activate", async () => { + await data.load(); + win.show_all(); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/mongo_connect.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/mongo_connect.js.snap index 52e8c378ff5..331004ef667 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/mongo_connect.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/mongo_connect.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: mongo_connect.js --- # Input @@ -16,13 +17,10 @@ MongoClient.connect( # Output ```js -MongoClient.connect( - "mongodb://localhost:27017/posts", - (err, db) => { - assert.equal(null, err); - db.close(); - }, -); +MongoClient.connect("mongodb://localhost:27017/posts", (err, db) => { + assert.equal(null, err); + db.close(); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls-with-comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls-with-comments.js.snap index 600fd71b6ec..74a5439291f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls-with-comments.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls-with-comments.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: pipe-function-calls-with-comments.js --- # Input @@ -90,7 +91,7 @@ expression: pipe-function-calls-with-comments.js ), ); process.exit(1); - },); + }); pipe( // add a descriptive comment here diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls.js.snap index 72604e08f2d..c8b1b6983e5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/functional-composition/pipe-function-calls.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: pipe-function-calls.js --- # Input @@ -63,7 +64,7 @@ expression: pipe-function-calls.js pipe(O.fromNullable(err.stack), O.getOrElse(constant(err.message))), ); process.exit(1); - },); + }); pipe(Changelog.timestampOfFirstCommit([[commit]]), O.toUndefined); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/ignore-2.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/ignore-2.js.snap index 113c2501f11..732fce92dfb 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/ignore/ignore-2.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ignore/ignore-2.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: ignore-2.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/break-parent.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/break-parent.js.snap index 628ce1a01a2..a2374914523 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/break-parent.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/break-parent.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: break-parent.js --- # Input @@ -36,22 +37,19 @@ true ```js ({ processors: [ - require( - "autoprefixer", - { - browsers: ["> 1%", "last 2 versions", "ie >= 11", "Firefox ESR"], - }, - ), + require("autoprefixer", { + browsers: ["> 1%", "last 2 versions", "ie >= 11", "Firefox ESR"], + }), require("postcss-url")({ url: (url) => url.startsWith("/") || /^[a-z]+:/.test(url) ? url : `/static/${url}`, - },), + }), ], }); true ? test({ a: 1, -},) :
{}, -); +foo(( + // foo +) => {}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/edge_case.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/edge_case.js.snap index 8789aedf857..0914af79713 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/edge_case.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/edge_case.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: edge_case.js --- # Input @@ -78,11 +79,12 @@ a( exports.examples = [ { - render: withGraphQLQuery( - "node(1234567890){image{uri}}", - function (container, data) { - return ( -
+ render: withGraphQLQuery("node(1234567890){image{uri}}", function ( + container, + data, + ) { + return ( +
- ); - }, - ), + ); + }), }, ]; -someReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReally.a([ - [], - // comment - [], -],); - -(function webpackUniversalModuleDefinition() {})( - this, - function (__WEBPACK_EXTERNAL_MODULE_85__, __WEBPACK_EXTERNAL_MODULE_115__) { - return /******/ (function (modules) { - // webpackBootstrap - /******/ - }) - /************************************************************************/ - /******/ ( - [ - /* 0 */ - /***/ function (module, exports, __webpack_require__) { - /***/ - }, - /* 1 */ - /***/ function (module, exports, __webpack_require__) { - /***/ - }, - /* 2 */ - /***/ function (module, exports, __webpack_require__) { - /***/ - }, - /******/ - ], - ); - }, +someReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReally.a( + [ + [], + // comment + [], + ], ); +(function webpackUniversalModuleDefinition() {})(this, function ( + __WEBPACK_EXTERNAL_MODULE_85__, + __WEBPACK_EXTERNAL_MODULE_115__, +) { + return /******/ (function (modules) { + // webpackBootstrap + /******/ + }) + /************************************************************************/ + /******/ ([ + /* 0 */ + /***/ function (module, exports, __webpack_require__) { + /***/ + }, + /* 1 */ + /***/ function (module, exports, __webpack_require__) { + /***/ + }, + /* 2 */ + /***/ function (module, exports, __webpack_require__) { + /***/ + }, + /******/ + ]); +}); + ``` # Lines exceeding max width of 80 characters ``` 2: SomethingVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong, 5: SomethingVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong: 1, - 31: someReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReally.a([ + 31: someReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReally.a( ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-lines.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-lines.js.snap index 1af01abb62e..35846405a3a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-lines.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-lines.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: empty-lines.js --- # Input @@ -18,7 +19,7 @@ all_verylongcall_verylongcall_verylongcall_verylongcall_verylongcall( ```js all_verylongcall_verylongcall_verylongcall_verylongcall_verylongcall((a, b) => { console.log(); -},); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-object.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-object.js.snap index 87875c5c26c..71085470ccd 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-object.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/empty-object.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: empty-object.js --- # Input @@ -44,7 +45,7 @@ func( func({ // comment -},); +}); func( {}, // comment @@ -52,7 +53,7 @@ func( func( {}, - // comment +// comment ); func( diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression-issue-2239.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression-issue-2239.js.snap index 1f081cc5b80..ca8989e0f0d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression-issue-2239.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression-issue-2239.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: function-expression-issue-2239.js --- # Input @@ -12,12 +13,11 @@ someFunctionCallWithBigArgumentsAndACallback(thisArgumentIsQuiteLong, function(c # Output ```js -someFunctionCallWithBigArgumentsAndACallback( - thisArgumentIsQuiteLong, - function (cool) { - return cool; - }, -); +someFunctionCallWithBigArgumentsAndACallback(thisArgumentIsQuiteLong, function ( + cool, +) { + return cool; +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression.js.snap index 443b4eb6bfd..077a29a63ec 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/function-expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: function-expression.js --- # Input @@ -30,24 +31,22 @@ function mySagas2() { # Output ```js function* mySagas() { - yield effects.takeEvery( - rexpress.actionTypes.REQUEST_START, - function* ({ id }) { - console.log(id); - yield rexpress.actions(store).writeHead(id, 400); - yield rexpress.actions(store).end(id, "pong"); - console.log("pong"); - }, - ); + yield effects.takeEvery(rexpress.actionTypes.REQUEST_START, function* ( + { id }, + ) { + console.log(id); + yield rexpress.actions(store).writeHead(id, 400); + yield rexpress.actions(store).end(id, "pong"); + console.log("pong"); + }); } function mySagas2() { - return effects.takeEvery( - rexpress.actionTypes.REQUEST_START, - function ({ id }) { - console.log(id); - }, - ); + return effects.takeEvery(rexpress.actionTypes.REQUEST_START, function ( + { id }, + ) { + console.log(id); + }); } ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/number-only-array.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/number-only-array.js.snap index d21d391bd87..afbc5d2f92d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/number-only-array.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/last-argument-expansion/number-only-array.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: number-only-array.js --- # Input @@ -13,17 +14,12 @@ instantiate(game, [ # Output ```js -instantiate( - game, - [ - transform([-0.7, 0.5, 0]), - render_colored_diffuse( - game.MaterialDiffuse, - game.Meshes["monkey_flat"], - [1, 1, 0.3, 1], - ), - ], -); +instantiate(game, [ + transform([-0.7, 0.5, 0]), + render_colored_diffuse(game.MaterialDiffuse, game.Meshes["monkey_flat"], [ + 1, 1, 0.3, 1, + ]), +]); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/member/expand.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/member/expand.js.snap index 4d0ed0155a8..de812e2ee08 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/member/expand.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/member/expand.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: expand.js --- # Input @@ -56,7 +57,7 @@ const promises = [ .catch((err) => { console.log(err); return null; - },), + }), redis.fetch(), other.fetch(), ]; @@ -70,7 +71,7 @@ const promises2 = [ .catch((err) => { console.log(err); return null; - },), + }), redis.fetch(), other.fetch(), ]; @@ -78,17 +79,17 @@ const promises2 = [ window.FooClient.setVars({ locale: getFooLocale({ page }), authorizationToken: data.token, -},).initVerify("foo_container"); +}).initVerify("foo_container"); window.something.FooClient.setVars({ locale: getFooLocale({ page }), authorizationToken: data.token, -},).initVerify("foo_container"); +}).initVerify("foo_container"); window.FooClient.something.setVars({ locale: getFooLocale({ page }), authorizationToken: data.token, -},).initVerify("foo_container"); +}).initVerify("foo_container"); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/bracket_0.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/bracket_0.js.snap index c5d1dde81cd..7788bf4ebf2 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/bracket_0.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/bracket_0.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: bracket_0.js --- # Input @@ -23,7 +24,7 @@ function a() { queryThenMutateDOM(() => { title = SomeThing.call(root, "someLongStringThatPushesThisTextReallyFar")[0]; - },); + }); } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/break-last-call.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/break-last-call.js.snap index 9b462eed91b..6c37a85cb30 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/break-last-call.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/break-last-call.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: break-last-call.js --- # Input @@ -51,81 +52,78 @@ export default (store) => { actionWith({ response, type: successType, - },), + }), ), (error) => next( actionWith({ type: failureType, error: error.message || "Something bad happened", - },), + }), ), ); }; -it( - "should group messages with same created time", - () => { - expect(groupMessages(messages).toJS()).toEqual({ - "11/01/2017 13:36": [ - { - message: "test", - messageType: "SMS", - status: "Unknown", - created: "11/01/2017 13:36", - }, - { - message: "test", - messageType: "Email", - status: "Unknown", - created: "11/01/2017 13:36", - }, - ], - "09/01/2017 17:25": [ - { - message: "te", - messageType: "SMS", - status: "Unknown", - created: "09/01/2017 17:25", - }, - { - message: "te", - messageType: "Email", - status: "Unknown", - created: "09/01/2017 17:25", - }, - ], - "11/01/2017 13:33": [ - { - message: "test", - messageType: "SMS", - status: "Unknown", - created: "11/01/2017 13:33", - }, - { - message: "test", - messageType: "Email", - status: "Unknown", - created: "11/01/2017 13:33", - }, - ], - "11/01/2017 13:37": [ - { - message: "test", - messageType: "SMS", - status: "Unknown", - created: "11/01/2017 13:37", - }, - { - message: "test", - messageType: "Email", - status: "Unknown", - created: "11/01/2017 13:37", - }, - ], - },); - }, -); +it("should group messages with same created time", () => { + expect(groupMessages(messages).toJS()).toEqual({ + "11/01/2017 13:36": [ + { + message: "test", + messageType: "SMS", + status: "Unknown", + created: "11/01/2017 13:36", + }, + { + message: "test", + messageType: "Email", + status: "Unknown", + created: "11/01/2017 13:36", + }, + ], + "09/01/2017 17:25": [ + { + message: "te", + messageType: "SMS", + status: "Unknown", + created: "09/01/2017 17:25", + }, + { + message: "te", + messageType: "Email", + status: "Unknown", + created: "09/01/2017 17:25", + }, + ], + "11/01/2017 13:33": [ + { + message: "test", + messageType: "SMS", + status: "Unknown", + created: "11/01/2017 13:33", + }, + { + message: "test", + messageType: "Email", + status: "Unknown", + created: "11/01/2017 13:33", + }, + ], + "11/01/2017 13:37": [ + { + message: "test", + messageType: "SMS", + status: "Unknown", + created: "11/01/2017 13:37", + }, + { + message: "test", + messageType: "Email", + status: "Unknown", + created: "11/01/2017 13:37", + }, + ], + }); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap index 6d988bbb7c6..894890d9364 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: comment.js --- # Input @@ -88,12 +89,12 @@ Something // Warm-up first measure().then(() => { SomethingLong(); -},); +}); measure() // Warm-up first .then(() => { SomethingLong(); -},); +}); const configModel = this.baseConfigurationService.getCache().consolidated.merge( // global/default values (do NOT modify) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed-merge.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed-merge.js.snap index 7a0016367c7..99b7f4b6173 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed-merge.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed-merge.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: computed-merge.js --- # Input @@ -29,13 +30,13 @@ window.Data[key]("foo") data[key]("foo") .then(() => console.log("bar")) .catch(() => console.log("baz")); -},); +}); [].forEach((key) => { data("foo")[key]("bar") .then(() => console.log("bar")) .catch(() => console.log("baz")); -},); +}); window.Data[key]("foo") .then(() => a) diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed.js.snap index 27f9b0153c7..ecd06e8391b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/computed.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: computed.js --- # Input @@ -17,12 +18,9 @@ nock(/test/) ```js nock(/test/) .matchHeader("Accept", "application/json")[httpMethodNock(method)]("/foo") - .reply( - 200, - { - foo: "bar", - }, - ); + .reply(200, { + foo: "bar", + }); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap index 1af6fba8439..2003cb40d36 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: first_long.js --- # Input @@ -53,8 +54,8 @@ export default function theFunction(action$, store) { value1: true, value2: false, value3: false, - },), - },) + }), + }) .filter((data) => theFilter(data)) .map(({ theType, ...data }) => theMap(theType, data)) .retryWhen((errors) => errors), @@ -65,7 +66,7 @@ function f() { return this._getWorker(workerOptions)({ filePath, hasteImplModulePath: this._options.hasteImplModulePath, - },) + }) .then((metadata) => { // `1` for truthy values instead of `true` to save cache space. fileMetadata[H.VISITED] = 1; @@ -76,7 +77,7 @@ function f() { setModule(metadataId, metadataModule); } fileMetadata[H.DEPENDENCIES] = metadata.dependencies || []; - },); + }); } ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap index 15922c4c1f9..fe230d707f6 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: inline_merge.js --- # Input @@ -30,10 +31,10 @@ var jqxhr = $.ajax("example.php") Object.keys( availableLocales({ test: true, - },), + }), ).forEach((locale) => { // ... -},); +}); this.layoutPartsToHide = this.utils.hashset( diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap index f0d3fc5f445..0d03bd47e65 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: issue-4125.js --- # Input @@ -211,13 +212,10 @@ d3 Object.keys(props) .filter((key) => (key in own) === false) - .reduce( - (a, key) => { - a[key] = props[key]; - return a; - }, - {}, - ); + .reduce((a, key) => { + a[key] = props[key]; + return a; + }, {}); point().x(4).y(3).z(6).plot(); @@ -254,12 +252,12 @@ function HelloWorld() { window.FooClient.setVars({ locale: getFooLocale({ page }), authorizationToken: data.token, - },).initVerify("foo_container"); + }).initVerify("foo_container"); fejax.ajax({ url: "/verification/", dataType: "json", - },).then( + }).then( (data) => { this.setState({ isLoading: false }); this.initWidget(data); @@ -295,15 +293,12 @@ action$ window.FooClient.setVars({ locale: getFooLocale({ page }), authorizationToken: data.token, -},).initVerify("foo_container"); - -it( - "gets triggered by mouseenter", - () => { - const wrapper = shallow(); - wrapper.dive().find(Button).prop(); - }, -); +}).initVerify("foo_container"); + +it("gets triggered by mouseenter", () => { + const wrapper = shallow(); + wrapper.dive().find(Button).prop(); +}); const a1 = x.a(true).b(null).c(123); const a2 = x.d("").e(``).f(g); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap index 04b6b195554..02b5b649c2f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: multiple-members.js --- # Input @@ -42,28 +43,22 @@ wrapper.find('SomewhatLongNodeName').prop('longPropFunctionName')('argument', 's # Output ```js if (testConfig.ENABLE_ONLINE_TESTS === "true") { - describe( - "POST /users/me/pet", - function () { - it( - "saves pet", - function () { - function assert(pet) { - expect(pet).to.have - .property("OwnerAddress") - .that.deep.equals({ - AddressLine1: "Alexanderstrasse", - AddressLine2: "", - PostalCode: "10999", - Region: "Berlin", - City: "Berlin", - Country: "DE", - },); - } - }, - ); - }, - ); + describe("POST /users/me/pet", function () { + it("saves pet", function () { + function assert(pet) { + expect(pet).to.have + .property("OwnerAddress") + .that.deep.equals({ + AddressLine1: "Alexanderstrasse", + AddressLine2: "", + PostalCode: "10999", + Region: "Berlin", + City: "Berlin", + Country: "DE", + }); + } + }); + }); } wrapper @@ -71,14 +66,14 @@ wrapper .prop("longPropFunctionName")() .then(function () { doSomething(); - },); + }); wrapper .find("SomewhatLongNodeName") .prop("longPropFunctionName")("argument") .then(function () { doSomething(); - },); + }); wrapper .find("SomewhatLongNodeName") @@ -88,7 +83,7 @@ wrapper )("argument") .then(function () { doSomething(); - },); + }); wrapper .find("SomewhatLongNodeName") @@ -98,7 +93,7 @@ wrapper ) .then(function () { doSomething(); - },); + }); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/object-literal.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/object-literal.js.snap index 4449210e0ce..ae0c3240c35 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/object-literal.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/object-literal.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: object-literal.js --- # Input @@ -30,7 +31,7 @@ of("test") error(err) { thrown = err; }, - },); + }); of("test") .pipe(throwIfEmpty()) @@ -38,7 +39,7 @@ of("test") get foo() { bar(); }, - },); + }); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-graphql/graphql-tag.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-graphql/graphql-tag.js.snap index 36dbbee657a..1f67c082319 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-graphql/graphql-tag.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/multiparser-graphql/graphql-tag.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: graphql-tag.js --- # Input @@ -307,7 +308,7 @@ ${USER_DETAILS_FRAGMENT} ${FRIENDS_FRAGMENT} ${generateFragment({ totally: "a good idea", -},)} +})} ${fragment}#comment diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/new-expression/with-member-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/new-expression/with-member-expression.js.snap index 1ee942c3fbe..5bd1380a68a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/new-expression/with-member-expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/new-expression/with-member-expression.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: with-member-expression.js --- # Input @@ -25,7 +26,7 @@ function functionName() { this._aVeryLongVariableNameToForceLineBreak = new this.Promise((resolve, reject) => { // do something - },); + }); } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/object-prop-break-in/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/object-prop-break-in/test.js.snap index f5aea980470..b72cf15ba93 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/object-prop-break-in/test.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/object-prop-break-in/test.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: test.js --- # Input @@ -41,33 +42,33 @@ ipsum` } ```js const a = classnames({ "some-prop": this.state.longLongLongLongLongLongLongLongLongTooLongProp, -},); +}); const b = classnames({ "some-prop": this.state.longLongLongLongLongLongLongLongLongTooLongProp === true, -},); +}); const c = classnames({ "some-prop": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo"], -},); +}); const d = classnames({ "some-prop": () => {}, -},); +}); const e = classnames({ "some-prop": function bar() {}, -},); +}); const f = classnames({ "some-prop": { foo: "bar", bar: "foo", foo: "bar", bar: "foo", foo: "bar" }, -},); +}); const g = classnames({ "some-prop": longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 1337, -},); +}); const h = { foo: "bar", diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/objects/range.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/objects/range.js.snap index 257b0da9eb7..a886300e441 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/objects/range.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/objects/range.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: range.js --- # Input @@ -22,19 +23,13 @@ group( # Output ```js -group( - concat([ - "(", - indent( - options.tabWidth, - concat([line, join(concat([",", line]), printed)]), - ), - options.trailingComma ? "," : "", - line, - ")", - ],), - { shouldBreak: true }, -); +group(concat([ + "(", + indent(options.tabWidth, concat([line, join(concat([",", line]), printed)])), + options.trailingComma ? "," : "", + line, + ")", +]), { shouldBreak: true }); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested-real.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested-real.js.snap index cb3cb324014..43855d0c089 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested-real.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested-real.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: nested-real.js --- # Input @@ -92,103 +93,93 @@ tap.test("RecordImport.advance", (t) => { # Output ```js -tap.test( - "RecordImport.advance", - (t) => { - const checkStates = (batches, states) => { - t.equal(batches.length, states.length); - for (const batch of batches) { - t.equal(batch.state, states.shift()); - t.ok(batch.getCurState().name(i18n)); - } - }; - - const batch = init.getRecordBatch(); - const dataFile = path.resolve(process.cwd(), "testData", "default.json"); - - const getBatches = (callback) => { - RecordImport.find( - {}, - "", - {}, - (err, batches) => { - callback( - null, - batches.filter( - (batch) => ( - batch.state !== "error" && batch.state !== "completed" - ), - ), - ); - }, +tap.test("RecordImport.advance", (t) => { + const checkStates = (batches, states) => { + t.equal(batches.length, states.length); + for (const batch of batches) { + t.equal(batch.state, states.shift()); + t.ok(batch.getCurState().name(i18n)); + } + }; + + const batch = init.getRecordBatch(); + const dataFile = path.resolve(process.cwd(), "testData", "default.json"); + + const getBatches = (callback) => { + RecordImport.find({}, "", {}, (err, batches) => { + callback( + null, + batches.filter( + (batch) => (batch.state !== "error" && batch.state !== "completed"), + ), ); - }; - - mockFS((callback) => { - batch.setResults( - [fs.createReadStream(dataFile)], - (err) => { - t.error(err, "Error should be empty."); - t.equal(batch.results.length, 6, "Check number of results"); - for (const result of batch.results) { - t.equal(result.result, "unknown"); - t.ok(result.data); - t.equal(result.data.lang, "en"); - } + }); + }; + + mockFS((callback) => { + batch.setResults( + [fs.createReadStream(dataFile)], + (err) => { + t.error(err, "Error should be empty."); + t.equal(batch.results.length, 6, "Check number of results"); + for (const result of batch.results) { + t.equal(result.result, "unknown"); + t.ok(result.data); + t.equal(result.data.lang, "en"); + } - getBatches((err, batches) => { - checkStates(batches, ["started"]); + getBatches((err, batches) => { + checkStates(batches, ["started"]); - RecordImport.advance((err) => { - t.error(err, "Error should be empty."); + RecordImport.advance((err) => { + t.error(err, "Error should be empty."); - getBatches((err, batches) => { - checkStates(batches, ["process.completed"]); + getBatches((err, batches) => { + checkStates(batches, ["process.completed"]); - // Need to manually move to the next step - batch.importRecords((err) => { - t.error(err, "Error should be empty."); + // Need to manually move to the next step + batch.importRecords((err) => { + t.error(err, "Error should be empty."); - getBatches((err, batches) => { - checkStates(batches, ["import.completed"]); + getBatches((err, batches) => { + checkStates(batches, ["import.completed"]); - RecordImport.advance((err) => { - t.error(err, "Error should be empty."); + RecordImport.advance((err) => { + t.error(err, "Error should be empty."); - getBatches((err, batches) => { - checkStates(batches, ["similarity.sync.completed"]); + getBatches((err, batches) => { + checkStates(batches, ["similarity.sync.completed"]); - RecordImport.advance((err) => { - t.error(err, "Error should be empty."); + RecordImport.advance((err) => { + t.error(err, "Error should be empty."); - t.ok(batch.getCurState().name(i18n)); + t.ok(batch.getCurState().name(i18n)); - getBatches((err, batches) => { - checkStates(batches, []); - t.end(); - callback(); - },); - },); + getBatches((err, batches) => { + checkStates(batches, []); + t.end(); + callback(); + }); + }); - t.ok(batch.getCurState().name(i18n)); - },); - },); + t.ok(batch.getCurState().name(i18n)); + }); + }); - t.ok(batch.getCurState().name(i18n)); - },); - },); + t.ok(batch.getCurState().name(i18n)); + }); + }); - t.ok(batch.getCurState().name(i18n)); - },); - },); + t.ok(batch.getCurState().name(i18n)); + }); + }); - t.ok(batch.getCurState().name(i18n)); - },); - }, - ); - },); - }, -); + t.ok(batch.getCurState().name(i18n)); + }); + }, + ); + }); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap index 889c17e4d4c..4fbcc99d35d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: nested.js --- # Input @@ -53,20 +54,20 @@ someObject.someFunction().then(function () { return someObject.someFunction().then(function () { return someObject.someFunction().then(function () { anotherFunction(); - },); - },); - },); - },); - },); - },); - },); - },); - },); - },); - },); - },); - },); -},); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/preserve-line/argument-list.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/preserve-line/argument-list.js.snap index 7dc1065212c..beb8cbce014 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/preserve-line/argument-list.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/preserve-line/argument-list.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: argument-list.js --- # Input @@ -244,16 +245,14 @@ comments( // Long Long Long Long Long Comment short3, - // More comments -); +// More comments -differentArgTypes( - () => { - return true; - }, - isTrue ? doSomething() : 12, ); +differentArgTypes(() => { + return true; +}, isTrue ? doSomething() : 12); + moreArgTypes( [1, 2, 3], { @@ -266,7 +265,8 @@ moreArgTypes( // Hello world again { name: "Hello World", age: 34 }, oneThing + anotherThing, - // Comment + // Comment + ), ); @@ -283,12 +283,9 @@ foo.apply( [1, 2], ); -bar.on( - "readable", - () => { - doStuff(); - }, -); +bar.on("readable", () => { + doStuff(); +}); foo( ["A, B"], @@ -305,37 +302,24 @@ doSomething.apply( ["Hello world 1", "Hello world 2", "Hello world 3"], ); -doAnotherThing( - "node", - { - solution_type, - time_frame, - }, -); +doAnotherThing("node", { + solution_type, + time_frame, +}); -stuff.doThing( - someStuff, - -1, - { - accept: (node) => doSomething(node), - }, -); +stuff.doThing(someStuff, -1, { + accept: (node) => doSomething(node), +}); -doThing( - someOtherStuff, - // This is important - true, - { - decline: (creditCard) => takeMoney(creditCard), - }, -); +doThing(someOtherStuff, +// This is important +true, { + decline: (creditCard) => takeMoney(creditCard), +}); -func( - () => { - thing(); - }, - { yes: true, no: 5 }, -); +func(() => { + thing(); +}, { yes: true, no: 5 }); doSomething( { tomorrow: maybe, today: never[always] }, diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/named-amd-module.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/named-amd-module.js.snap index 04ef08bad69..f9452a83b93 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/named-amd-module.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/named-amd-module.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: named-amd-module.js --- # Input @@ -15,13 +16,9 @@ define("foo/title", # Output ```js -define( - "foo/title", - ["my/cart", "my/inventory"], - function (cart, inventory) { - //Define foo/title object in here. - }, -); +define("foo/title", ["my/cart", "my/inventory"], function (cart, inventory) { + //Define foo/title object in here. +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/require.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/require.js.snap index 5665ec16bcf..9ef59eafe1f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/require.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/require-amd/require.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: require.js --- # Input @@ -42,55 +43,49 @@ define( # Output ```js -require( - [ - "jquery", - "common/global.context", - "common/log.event", - "some_project/square", - "some_project/rectangle", - "some_project/triangle", - "some_project/circle", - "some_project/star", - ], - function ( - $, - Context, - EventLogger, - Square, - Rectangle, - Triangle, - Circle, - Star, - ) { - console.log("some code"); - }, -); +require([ + "jquery", + "common/global.context", + "common/log.event", + "some_project/square", + "some_project/rectangle", + "some_project/triangle", + "some_project/circle", + "some_project/star", +], function ( + $, + Context, + EventLogger, + Square, + Rectangle, + Triangle, + Circle, + Star, +) { + console.log("some code"); +}); -define( - [ - "jquery", - "common/global.context", - "common/log.event", - "some_project/square", - "some_project/rectangle", - "some_project/triangle", - "some_project/circle", - "some_project/star", - ], - function ( - $, - Context, - EventLogger, - Square, - Rectangle, - Triangle, - Circle, - Star, - ) { - console.log("some code"); - }, -); +define([ + "jquery", + "common/global.context", + "common/log.event", + "some_project/square", + "some_project/rectangle", + "some_project/triangle", + "some_project/circle", + "some_project/star", +], function ( + $, + Context, + EventLogger, + Square, + Rectangle, + Triangle, + Circle, + Star, +) { + console.log("some code"); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/return/comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/return/comment.js.snap index 090ecd76c96..a7fca1a276b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/return/comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/return/comment.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: comment.js --- # Input @@ -89,7 +90,7 @@ fn(function f() { // comment .bar() ); -},); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/expressions.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/expressions.js.snap index 593329529bb..ec8694a331d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/expressions.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/template-literals/expressions.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: expressions.js --- # Input @@ -109,15 +110,12 @@ console.log( `\nApparently jetbrains changed the release artifact for ${app.name}@${app.jetbrains.version}.\n`, ); -descirbe( - "something", - () => { - test( - `{pass: false} expect(${small}).toBeGreaterThanOrEqual(${big})`, - () => {}, - ); - }, -); +descirbe("something", () => { + test( + `{pass: false} expect(${small}).toBeGreaterThanOrEqual(${big})`, + () => {}, + ); +}); throw new Error( `pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.`, @@ -137,6 +135,6 @@ throw new Error( 34: return `${process.env.OPENID_URL}/something/something/something?${Object.keys( 44: `Trying update appcast for ${app.name} (${app.cask.appcast}) -> (${app.cask.appcastGenerated})`, 52: `\nApparently jetbrains changed the release artifact for ${app.name}@${app.jetbrains.version}.\n`, - 66: `pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.`, + 63: `pretty-format: Option "theme" has a key "${key}" whose value "${value}" is undefined in ansi-styles.`, ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/template/graphql.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/template/graphql.js.snap index b0e16121208..c76825a8eed 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/template/graphql.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/template/graphql.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: graphql.js --- # Input @@ -36,10 +37,10 @@ module.exports = Relay.QL` fragment on RelatedNode @relay(plural: true) { __typename - ${OptimalSolutionsSection.getFragment( - "node", - { solution_type, time_frame }, - )} + ${OptimalSolutionsSection.getFragment("node", { + solution_type, + time_frame, + })} } `, }, diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/template/indent.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/template/indent.js.snap index 4cd1f0783f4..7cc24c81cc3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/template/indent.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/template/indent.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: indent.js --- # Input @@ -41,7 +42,7 @@ line n ${foo({ many: keys, many: keys, - },)} + })} line n + 1 line n + 2 line n + n diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/ternaries/indent.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/ternaries/indent.js.snap index eca52954e8a..1da157d4d91 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/ternaries/indent.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/ternaries/indent.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: indent.js --- # Input @@ -243,7 +244,7 @@ a ? { a ? { a: a({ a: 0, - },), + }), } : [ 0, a(), @@ -254,7 +255,7 @@ a ? { }, a ? a() : a({ a: 0, - },), + }), ), a() ? { a: a(), @@ -277,7 +278,7 @@ a ? { { a: 0, }, - ],); + ]); })( a ? function (a) { return function () { diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap index 6e543542e28..e20c6e21235 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_async.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: angular_async.js --- # Input @@ -46,7 +47,7 @@ function x() { async(() => {}) } beforeEach( async(() => { // code - },), + }), ); beforeEach((done) => foo().bar().bar()); @@ -54,7 +55,7 @@ beforeEach((done) => foo().bar().bar()); afterAll( async(() => { console.log("Hello"); - },), + }), ); afterAll((done) => foo().bar().bar()); @@ -63,14 +64,14 @@ it( "should create the app", async(() => { //code - },), + }), ); it( "does something really long and complicated so I have to write a very long name for the test", async(() => { // code - },), + }), ); /* diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap index 35c00121d6d..ae4ece92245 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_fakeAsync.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: angular_fakeAsync.js --- # Input @@ -36,27 +37,27 @@ function x() { fakeAsync(() => {}) } beforeEach( fakeAsync(() => { // code - },), + }), ); afterAll( fakeAsync(() => { console.log("Hello"); - },), + }), ); it( "should create the app", fakeAsync(() => { //code - },), + }), ); it( "does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => { // code - },), + }), ); it( diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap index fa4adbdafe0..b0d21872109 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angular_waitForAsync.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: angular_waitForAsync.js --- # Input @@ -36,27 +37,27 @@ function x() { waitForAsync(() => {}) } beforeEach( waitForAsync(() => { // code - },), + }), ); afterAll( waitForAsync(() => { console.log("Hello"); - },), + }), ); it( "should create the app", waitForAsync(() => { //code - },), + }), ); it( "does something really long and complicated so I have to write a very long name for the test", waitForAsync(() => { // code - },), + }), ); it( diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap index f32f2887133..32f5f6a0b31 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/angularjs_inject.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: angularjs_inject.js --- # Input @@ -38,34 +39,34 @@ function x() { inject(() => {}) } beforeEach( inject(($fooService, $barService) => { // code - },), + }), ); afterAll( inject(($fooService, $barService) => { console.log("Hello"); - },), + }), ); it( "should create the app", inject(($fooService, $barService) => { //code - },), + }), ); it( "does something really long and complicated so I have to write a very long name for the test", inject(() => { // code - },), + }), ); it( "does something really long and complicated so I have to write a very long name for the test", inject(($fooServiceLongName, $barServiceLongName) => { // code - },), + }), ); /* diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap index 23cd5435328..7a82d8d40b8 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: jest-each.js --- # Input @@ -76,31 +77,19 @@ a|b|expected ${11} | ${1}|${222} ${1 - 1}|${2 + 2}|${3333} ${2 + 1 + 2}|${1111}|${3} -`( - "$a + $b", - ({ a, b, expected }) => { - test( - `returns ${expected}`, - () => { - expect(a + b).toBe(expected); - }, - ); - - test( - `returned value not be greater than ${expected}`, - () => { - expect(a + b).not.toBeGreaterThan(expected); - }, - ); - - test( - `returned value not be less than ${expected}`, - () => { - expect(a + b).not.toBeLessThan(expected); - }, - ); - }, -); +`("$a + $b", ({ a, b, expected }) => { + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected); + }); + + test(`returned value not be greater than ${expected}`, () => { + expect(a + b).not.toBeGreaterThan(expected); + }); + + test(`returned value not be less than ${expected}`, () => { + expect(a + b).not.toBeLessThan(expected); + }); +}); describe.only.each` a|b|expected @@ -130,26 +119,23 @@ ${11111111111} | ${a() ${1} | ${2} | ${3} ${2} | ${1} | ${3}`; -describe.each([1, 2, 3])( - "test", - (a) => { - expect(a).toBe(a); - }, -); +describe.each([1, 2, 3])("test", (a) => { + expect(a).toBe(a); +}); -test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( - ".add(%i, %i)", - (a, b, expected) => { - expect(a + b).toBe(expected); - }, -); +test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(".add(%i, %i)", ( + a, + b, + expected, +) => { + expect(a + b).toBe(expected); +}); -test.each([{ a: "1", b: 1 }, { a: "2", b: 2 }, { a: "3", b: 3 }])( - "test", - ({ a, b }) => { - expect(Number(a)).toBe(b); - }, -); +test.each([{ a: "1", b: 1 }, { a: "2", b: 2 }, { a: "3", b: 3 }])("test", ( + { a, b }, +) => { + expect(Number(a)).toBe(b); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap index d5c8efc56a1..b5bf6118e3e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: test_declarations.js --- # Input @@ -215,15 +216,12 @@ it( }, ); -it( - `handles +it(`handles some newlines - does something really long and complicated so I have to write a very long name for the test`, - () => { - console.log("hello!"); - }, -); + does something really long and complicated so I have to write a very long name for the test`, () => { + console.log("hello!"); +}); test( "does something really long and complicated so I have to write a very long name for the test", @@ -242,24 +240,18 @@ test( describe( "does something really long and complicated so I have to write a very long name for the describe block", () => { - it( - "an example test", - (done) => { - console.log("hello!"); - }, - ); + it("an example test", (done) => { + console.log("hello!"); + }); }, ); describe( `does something really long and complicated so I have to write a very long name for the describe block`, () => { - it( - `an example test`, - (done) => { - console.log("hello!"); - }, - ); + it(`an example test`, (done) => { + console.log("hello!"); + }); }, ); @@ -503,48 +495,48 @@ it( 25: "does something really long and complicated so I have to write a very long name for the test", 32: `does something really long and complicated so I have to write a very long name for the test`, 39: `{foo + bar} does something really long and complicated so I have to write a very long name for the test`, - 49: does something really long and complicated so I have to write a very long name for the test`, - 56: "does something really long and complicated so I have to write a very long name for the test", - 63: `does something really long and complicated so I have to write a very long name for the test`, - 70: "does something really long and complicated so I have to write a very long name for the describe block", - 82: `does something really long and complicated so I have to write a very long name for the describe block`, - 94: "does something really long and complicated so I have to write a very long name for the describe block", - 99: "does something really long and complicated so I have to write a very long name for the describe block", - 104: `does something really long and complicated so I have to write a very long name for the test`, - 109: `does something really long and complicated so I have to write a very long name for the test`, - 114: "does something really long and complicated so I have to write a very long name for the describe block", - 119: "does something really long and complicated so I have to write a very long name for the describe block", - 124: "does something really long and complicated so I have to write a very long name for the test", - 131: `does something really long and complicated so I have to write a very long name for the test`, - 138: `does something really long and complicated so I have to write a very long name for the test`, - 143: `does something really long and complicated so I have to write a very long name for the test`, - 148: `does something really long and complicated so I have to write a very long name for the test`, - 153: "does something really long and complicated so I have to write a very long name for the describe block", - 158: "does something really long and complicated so I have to write a very long name for the describe block", - 163: `does something really long and complicated so I have to write a very long name for the test`, - 168: "does something really long and complicated so I have to write a very long name for the test", - 173: "does something really long and complicated so I have to write a very long name for the test", - 178: `does something really long and complicated so I have to write a very long name for the test`, - 183: "does something really long and complicated so I have to write a very long name for the test", - 188: `does something really long and complicated so I have to write a very long name for the test`, - 193: "does something really long and complicated so I have to write a very long name for the test", - 198: `does something really long and complicated so I have to write a very long name for the test`, - 203: "does something really long and complicated so I have to write a very long name for the test", - 208: `does something really long and complicated so I have to write a very long name for the test`, - 213: "does something really long and complicated so I have to write a very long name for the testThis is a very", - 218: `does something really long and complicated so I have to write a very long name for the testThis is a very`, - 223: "does something really long and complicated so I have to write a very long name for the test", - 228: `does something really long and complicated so I have to write a very long name for the test`, - 233: "does something really long and complicated so I have to write a very long name for the test", - 238: `does something really long and complicated so I have to write a very long name for the test`, - 245: "does something really long and complicated so I have to write a very long name for the test", - 253: "does something really long and complicated so I have to write a very long name for the test", - 260: "does something really long and complicated so I have to write a very long name for the test", - 267: "does something really long and complicated so I have to write a very long name for the test", - 272: "does something really long and complicated so I have to write a very long name for the test", - 277: "does something really long and complicated so I have to write a very long name for the testThis is a very", - 282: "does something really long and complicated so I have to write a very long name for the test", - 287: "does something really long and complicated so I have to write a very long name for the test", - 297: does something really long and complicated so I have to write a very long name for the test`, + 48: does something really long and complicated so I have to write a very long name for the test`, () => { + 53: "does something really long and complicated so I have to write a very long name for the test", + 60: `does something really long and complicated so I have to write a very long name for the test`, + 67: "does something really long and complicated so I have to write a very long name for the describe block", + 76: `does something really long and complicated so I have to write a very long name for the describe block`, + 85: "does something really long and complicated so I have to write a very long name for the describe block", + 90: "does something really long and complicated so I have to write a very long name for the describe block", + 95: `does something really long and complicated so I have to write a very long name for the test`, + 100: `does something really long and complicated so I have to write a very long name for the test`, + 105: "does something really long and complicated so I have to write a very long name for the describe block", + 110: "does something really long and complicated so I have to write a very long name for the describe block", + 115: "does something really long and complicated so I have to write a very long name for the test", + 122: `does something really long and complicated so I have to write a very long name for the test`, + 129: `does something really long and complicated so I have to write a very long name for the test`, + 134: `does something really long and complicated so I have to write a very long name for the test`, + 139: `does something really long and complicated so I have to write a very long name for the test`, + 144: "does something really long and complicated so I have to write a very long name for the describe block", + 149: "does something really long and complicated so I have to write a very long name for the describe block", + 154: `does something really long and complicated so I have to write a very long name for the test`, + 159: "does something really long and complicated so I have to write a very long name for the test", + 164: "does something really long and complicated so I have to write a very long name for the test", + 169: `does something really long and complicated so I have to write a very long name for the test`, + 174: "does something really long and complicated so I have to write a very long name for the test", + 179: `does something really long and complicated so I have to write a very long name for the test`, + 184: "does something really long and complicated so I have to write a very long name for the test", + 189: `does something really long and complicated so I have to write a very long name for the test`, + 194: "does something really long and complicated so I have to write a very long name for the test", + 199: `does something really long and complicated so I have to write a very long name for the test`, + 204: "does something really long and complicated so I have to write a very long name for the testThis is a very", + 209: `does something really long and complicated so I have to write a very long name for the testThis is a very`, + 214: "does something really long and complicated so I have to write a very long name for the test", + 219: `does something really long and complicated so I have to write a very long name for the test`, + 224: "does something really long and complicated so I have to write a very long name for the test", + 229: `does something really long and complicated so I have to write a very long name for the test`, + 236: "does something really long and complicated so I have to write a very long name for the test", + 244: "does something really long and complicated so I have to write a very long name for the test", + 251: "does something really long and complicated so I have to write a very long name for the test", + 258: "does something really long and complicated so I have to write a very long name for the test", + 263: "does something really long and complicated so I have to write a very long name for the test", + 268: "does something really long and complicated so I have to write a very long name for the testThis is a very", + 273: "does something really long and complicated so I have to write a very long name for the test", + 278: "does something really long and complicated so I have to write a very long name for the test", + 288: does something really long and complicated so I have to write a very long name for the test`, ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/throw_statement/comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/throw_statement/comment.js.snap index ebd82401525..1040cce7b8a 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/throw_statement/comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/throw_statement/comment.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: comment.js --- # Input @@ -50,7 +51,7 @@ fn(function f() { // comment .bar() ); -},); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/function-calls.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/function-calls.js.snap index 1d07dd5e965..fa6af11eda8 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/function-calls.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/function-calls.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: function-calls.js --- # Input @@ -43,12 +44,9 @@ a( a("long-nested-value", "long-nested-value2", "long-nested-value3"), ); -a.b().c( - { - d, - }, - () => {}, -); +a.b().c({ + d, +}, () => {}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/jsx.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/jsx.js.snap index 910967d8658..c941b01a2d6 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/jsx.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/jsx.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: jsx.js --- # Input @@ -21,7 +22,7 @@ expression: jsx.js () => doSomething({ foo: bar, - },) + }) } />; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/trailing_whitespace.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/trailing_whitespace.js.snap index fb4c375a2c1..d786f3102f6 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/trailing_whitespace.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/trailing-comma/trailing_whitespace.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: trailing_whitespace.js --- # Input @@ -59,7 +60,7 @@ let example = [ foo( {}, - // Comment +// Comment ); o = @@ -89,17 +90,13 @@ function supersupersupersuperLongF( a; } -this.getAttribute( - function (s) - /*string*/ { - console.log(); - }, -); -this.getAttribute( - function (s) /*string*/ { - console.log(); - }, -); +this.getAttribute(function (s) +/*string*/ { + console.log(); +}); +this.getAttribute(function (s) /*string*/ { + console.log(); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/variable_declarator/multiple.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/variable_declarator/multiple.js.snap index e91c3e9ab5c..65e37830ac4 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/variable_declarator/multiple.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/variable_declarator/multiple.js.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: multiple.js --- # Input @@ -51,12 +52,9 @@ var templateTagsMapping = { "%{itemContentMetaTextViews}": "views", }, separator = '', - templateTagsList = $.map( - templateTagsMapping, - function (value, key) { - return key; - }, - ), + templateTagsList = $.map(templateTagsMapping, function (value, key) { + return key; + }), data; ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap index b91fc1e3fa3..2c44ea8f9b3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/argument-expansion/argument_expansion.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: argument_expansion.ts --- # Input @@ -40,61 +41,37 @@ const bar8 = [1,2,3].reduce((carry, value) => { # Output ```js -const bar1 = [1, 2, 3].reduce( - (carry, value) => { - return [...carry, value]; - }, - ([] as unknown) as number[], -); - -const bar2 = [1, 2, 3].reduce( - (carry, value) => { - return [...carry, value]; - }, - >[], -); - -const bar3 = [1, 2, 3].reduce( - (carry, value) => { - return [...carry, value]; - }, - ([1, 2, 3] as unknown) as number[], -); - -const bar4 = [1, 2, 3].reduce( - (carry, value) => { - return [...carry, value]; - }, - >[1, 2, 3], -); - -const bar5 = [1, 2, 3].reduce( - (carry, value) => { - return { ...carry, [value]: true }; - }, - ({} as unknown) as { [key: number]: boolean }, -); - -const bar6 = [1, 2, 3].reduce( - (carry, value) => { - return { ...carry, [value]: true }; - }, - <{ [key: number]: boolean }>{}, -); - -const bar7 = [1, 2, 3].reduce( - (carry, value) => { - return { ...carry, [value]: true }; - }, - ({ 1: true } as unknown) as { [key: number]: boolean }, -); - -const bar8 = [1, 2, 3].reduce( - (carry, value) => { - return { ...carry, [value]: true }; - }, - <{ [key: number]: boolean }>{ 1: true }, -); +const bar1 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, ([] as unknown) as number[]); + +const bar2 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, >[]); + +const bar3 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] as unknown) as number[]); + +const bar4 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, >[1, 2, 3]); + +const bar5 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, ({} as unknown) as { [key: number]: boolean }); + +const bar6 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, <{ [key: number]: boolean }>{}); + +const bar7 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, ({ 1: true } as unknown) as { [key: number]: boolean }); + +const bar8 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, <{ [key: number]: boolean }>{ 1: true }); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/arrow/arrow_regression.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/arrow/arrow_regression.ts.snap index e7c500654fb..8ceca727ed5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/arrow/arrow_regression.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/arrow/arrow_regression.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: arrow_regression.ts --- # Input @@ -30,12 +31,9 @@ const bar = (...varargs: any[]) => { const foo = (x: string): void => (bar(x, () => {}, () => {})); -app.get( - "/", - (req, res): void => { - res.send("Hello world"); - }, -); +app.get("/", (req, res): void => { + res.send("Hello world"); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap index c57f474a4dd..84e34ead9aa 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/as.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: as.ts --- # Input @@ -79,12 +80,10 @@ async function g1() { } ({}) as X; () => ({}) as X; -const state = JSON.stringify( - { - next: window.location.href, - nonce, - } as State, -); +const state = JSON.stringify({ + next: window.location.href, + nonce, +} as State); (foo.bar as Baz) = [bar]; (foo.bar as any)++; @@ -122,8 +121,8 @@ const iter2 = createIterator( # Lines exceeding max width of 80 characters ``` - 44: const value1 = thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; - 45: const value2 = thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; - 54: const value5 = thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [ + 42: const value1 = thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; + 43: const value2 = thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; + 52: const value5 = thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [ ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment.ts.snap index b271d90ce23..74ef8070173 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: assignment.ts --- # Input @@ -61,25 +62,19 @@ const TYPE_MAP = { this.previewPlayerHandle = ( - setInterval( - async () => { - if (this.previewIsPlaying) { - await this.fetchNextPreviews(); - this.currentPreviewIndex++; - } - }, - this.refreshDelay, - ) as unknown + setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } + }, this.refreshDelay) as unknown ) as number; this.intervalID = ( - setInterval( - () => { - self.step(); - }, - 30, - ) as unknown + setInterval(() => { + self.step(); + }, 30) as unknown ) as number; ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap index 4f6446c0d57..c03ed1255b3 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: assignment2.ts --- # Input @@ -44,17 +45,14 @@ const defaultMaskGetter = $parse(attrs[directiveName]) as ( (this.configuration as any) = (this.editor as any) = (this.editorBody as any) = undefined; -angular.module("foo").directive( - "formIsolator", - () => { - return { - name: "form", - controller: class FormIsolatorController { - $addControl = angular.noop; - } as ng.IControllerConstructor, - }; - }, -); +angular.module("foo").directive("formIsolator", () => { + return { + name: "form", + controller: class FormIsolatorController { + $addControl = angular.noop; + } as ng.IControllerConstructor, + }; +}); (this.selectorElem as any) = this.multiselectWidget = this.initialValues = undefined; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10848.tsx.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10848.tsx.snap index a1f7e2b3a37..ddf138d2302 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10848.tsx.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10848.tsx.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: issue-10848.tsx --- # Input @@ -121,10 +122,10 @@ const Query: FunctionComponent = ( }, ) => children( - useQuery( - { type, resource, payload }, - { ...options, withDeclarativeSideEffectsSupport: true }, - ), + useQuery({ type, resource, payload }, { + ...options, + withDeclarativeSideEffectsSupport: true, + }), ); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/hug-args.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/hug-args.ts.snap index 7c150801afa..8bb6332d9cd 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/hug-args.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/hug-args.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: hug-args.ts --- # Input @@ -31,28 +32,22 @@ postMessages( # Output ```js -postMessage( - { - context: item.context, - topic: item.topic, - }, -); +postMessage({ + context: item.context, + topic: item.topic, +}); -window.postMessage( +window.postMessage({ + context: item.context, + topic: item.topic, +} as IActionMessage); + +postMessages([ { context: item.context, topic: item.topic, - } as IActionMessage, -); - -postMessages( - [ - { - context: item.context, - topic: item.topic, - }, - ], -); + }, +]); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/empty-method-body.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/empty-method-body.ts.snap index c8772dc780f..eeb65571a75 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/class/empty-method-body.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/class/empty-method-body.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: empty-method-body.ts --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/classes/break.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/classes/break.ts.snap index 6591f8f2f2d..613bb43793c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/classes/break.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/classes/break.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: break.ts --- # Input @@ -81,7 +82,7 @@ class InMemoryAppender extends log4javascript.Appender class Foo extends Immutable.Record({ ipaddress: "", -},) { +}) { ipaddress: string; } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap index e0d481959e7..59dec9b5db6 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/method_types.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: method_types.ts --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap index 3ac1a3bd151..a43c17d76c5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/methods.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: methods.ts --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/custom/typeParameters/variables.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/custom/typeParameters/variables.ts.snap index 472f8da7539..a929ed9539e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/custom/typeParameters/variables.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/custom/typeParameters/variables.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: variables.ts --- # Input @@ -54,11 +55,9 @@ const baaaaaaaaaaaaaaaar: SomeThing< const isAnySuccessfulAttempt$: Observable< boolean > = this._quizService.isAnySuccessfulAttempt$().pipe( - tap( - (isAnySuccessfulAttempt: boolean) => { - this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; - }, - ), + tap((isAnySuccessfulAttempt: boolean) => { + this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; + }), ); const isAnySuccessfulAttempt2$: Observable< boolean diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls-with-comments.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls-with-comments.ts.snap index 14bfbe6882e..0c32c65401b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls-with-comments.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls-with-comments.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: pipe-function-calls-with-comments.ts --- # Input @@ -81,18 +82,16 @@ expression: pipe-function-calls-with-comments.ts ), )() .then(messageResponse(logger, msg)) - .catch( - (err: Error) => { - logger.error( - pipe( - // add a descriptive comment here - O.fromNullable(err.stack), - O.getOrElse(constant(err.message)), - ), - ); - process.exit(1); - }, - ); + .catch((err: Error) => { + logger.error( + pipe( + // add a descriptive comment here + O.fromNullable(err.stack), + O.getOrElse(constant(err.message)), + ), + ); + process.exit(1); + }); pipe( // add a descriptive comment here diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls.ts.snap index 53ce5dc5f8b..1df135ef1d5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/functional-composition/pipe-function-calls.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: pipe-function-calls.ts --- # Input @@ -37,14 +38,12 @@ expression: pipe-function-calls.ts TE.chain(flow(publishServiceEvent(analytics), TE.mapLeft(nackFromError))), )() .then(messageResponse(logger, msg)) - .catch( - (err: Error) => { - logger.error( - pipe(O.fromNullable(err.stack), O.getOrElse(constant(err.message))), - ); - process.exit(1); - }, - ); + .catch((err: Error) => { + logger.error( + pipe(O.fromNullable(err.stack), O.getOrElse(constant(err.message))), + ); + process.exit(1); + }); })(); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/break.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/break.ts.snap index 58f9ee5ddf4..dfc73dcbce5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/break.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/break.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: break.ts --- # Input @@ -20,22 +21,18 @@ export default class AddAssetHtmlPlugin { ```js export default class AddAssetHtmlPlugin { apply(compiler: WebpackCompilerType) { - compiler.plugin( - "compilation", - (compilation: WebpackCompilationType) => { - compilation.plugin( - "html-webpack-plugin-before-html", - (callback: Callback) => { - addAllAssetsToCompilation( - this.assets, - compilation, - htmlPluginData, - callback, - ); - }, + compiler.plugin("compilation", (compilation: WebpackCompilationType) => { + compilation.plugin("html-webpack-plugin-before-html", ( + callback: Callback, + ) => { + addAllAssetsToCompilation( + this.assets, + compilation, + htmlPluginData, + callback, ); - }, - ); + }); + }); } } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/edge_case.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/edge_case.ts.snap index bfb3e6e8dd3..4413e470f95 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/edge_case.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/last-argument-expansion/edge_case.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: edge_case.ts --- # Input @@ -24,10 +25,10 @@ var listener = DOM.listen( "click", sigil, (event: JavelinEvent): void => - BanzaiLogger.log( - config, - { ...logData, ...DataStore.get(event.getNode(sigil)) }, - ), + BanzaiLogger.log(config, { + ...logData, + ...DataStore.get(event.getNode(sigil)), + }), ); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap index a99f21f46fa..a09177d4015 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: comment.ts --- # Input @@ -20,18 +21,16 @@ this.firebase.object(`/shops/${shopLocation.shop}`) ```js this.firebase.object(`/shops/${shopLocation.shop}`) // keep distance info -.first( - ( - shop: ShopQueryResult, - index: number, - source: Observable, - ): any => { - // add distance to result - const s = shop; - s.distance = shopLocation.distance; - return s; - }, -); +.first(( + shop: ShopQueryResult, + index: number, + source: Observable, +): any => { + // add distance to result + const s = shop; + s.distance = shopLocation.distance; + return s; +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/class-method.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/class-method.ts.snap index 21adc167dc8..5dcd7dca42d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/class-method.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeparams/class-method.ts.snap @@ -1,5 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +assertion_line: 182 expression: class-method.ts --- # Input @@ -132,7 +133,7 @@ export class Thing3 implements OtherThing { return someVar.method(); } return false; - },); + }); } export class Thing4 implements OtherThing { @@ -194,23 +195,23 @@ export class Thing11 implements OtherThing { // regular non-arrow functions export class Thing12 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType): Provider { - return type; - }, - ); + do: (type: Type) => Provider = memoize(function ( + type: ObjectType, + ): Provider { + return type; + }); } export class Thing13 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType): Provider { - const someVar = doSomething(type); - if (someVar) { - return someVar.method(); - } - return false; - }, - ); + do: (type: Type) => Provider = memoize(function ( + type: ObjectType, + ): Provider { + const someVar = doSomething(type); + if (someVar) { + return someVar.method(); + } + return false; + }); } export class Thing14 implements OtherThing { @@ -220,75 +221,69 @@ export class Thing14 implements OtherThing { return someVar.method(); } return false; - },); + }); } export class Thing15 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType): Provider { - return type.doSomething(); - }, - ); + do: (type: Type) => Provider = memoize(function ( + type: ObjectType, + ): Provider { + return type.doSomething(); + }); } export class Thing16 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType): Provider { - return type.doSomething(); - }, - ); + do: (type: Type) => Provider = memoize(function ( + type: ObjectType, + ): Provider { + return type.doSomething(); + }); } export class Thing17 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType): Provider { - return >type.doSomething(); - }, - ); + do: (type: Type) => Provider = memoize(function ( + type: ObjectType, + ): Provider { + return >type.doSomething(); + }); } export class Thing18 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType) { - return >type.doSomething(); - }, - ); + do: (type: Type) => Provider = memoize(function (type: ObjectType) { + return >type.doSomething(); + }); } export class Thing19 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType) { - return >type.doSomething( - withArgs, - soIt, - does, - not, - fit, - ).extraCall(); - }, - ); + do: (type: Type) => Provider = memoize(function (type: ObjectType) { + return >type.doSomething( + withArgs, + soIt, + does, + not, + fit, + ).extraCall(); + }); } export class Thing20 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType) { - return type.doSomething(); - }, - ); + do: (type: Type) => Provider = memoize(function (type: ObjectType) { + return type.doSomething(); + }); } export class Thing21 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (veryLongArgName: ObjectType): Provider { - return veryLongArgName; - }, - ); + do: (type: Type) => Provider = memoize(function ( + veryLongArgName: ObjectType, + ): Provider { + return veryLongArgName; + }); } export class Thing22 implements OtherThing { - do: (type: Type) => Provider = memoize( - function (type: ObjectType): Provider {}, - ); + do: (type: Type) => Provider = memoize(function ( + type: ObjectType, + ): Provider {}); } // case from https://github.com/prettier/prettier/issues/2581 diff --git a/crates/rome_js_formatter/tests/specs/ts/call_expression.ts b/crates/rome_js_formatter/tests/specs/ts/call_expression.ts new file mode 100644 index 00000000000..9fe943873d2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/ts/call_expression.ts @@ -0,0 +1,10 @@ +app.get("/", (req, res): void => { + res.send("Hello World!"); +}) + + +export class Thing implements OtherThing { + do: (type: Type) => Provider = memoize( + (type: ObjectType): Provider => {} + ); +} \ No newline at end of file diff --git a/crates/rome_js_formatter/tests/specs/ts/call_expression.ts.snap b/crates/rome_js_formatter/tests/specs/ts/call_expression.ts.snap new file mode 100644 index 00000000000..16db0f0daaf --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/ts/call_expression.ts.snap @@ -0,0 +1,34 @@ +--- +source: crates/rome_js_formatter/tests/spec_test.rs +assertion_line: 257 +expression: call_expression.ts +--- +# Input +app.get("/", (req, res): void => { + res.send("Hello World!"); +}) + + +export class Thing implements OtherThing { + do: (type: Type) => Provider = memoize( + (type: ObjectType): Provider => {} + ); +} +============================= +# Outputs +## Output 1 +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +----- +app.get("/", (req, res): void => { + res.send("Hello World!"); +}); + +export class Thing implements OtherThing { + do: (type: Type) => Provider = memoize( + (type: ObjectType): Provider => {}, + ); +} + diff --git a/crates/rome_js_syntax/src/union_ext.rs b/crates/rome_js_syntax/src/union_ext.rs index 8868b901cfc..7cf1a7867bc 100644 --- a/crates/rome_js_syntax/src/union_ext.rs +++ b/crates/rome_js_syntax/src/union_ext.rs @@ -4,7 +4,7 @@ use crate::{ TsAnyVariableAnnotation, TsImplementsClause, TsReturnTypeAnnotation, TsTypeAnnotation, TsTypeParameters, }; -use rome_rowan::SyntaxResult; +use rome_rowan::{AstSeparatedList, SyntaxResult}; impl JsAnyClass { pub fn abstract_token(&self) -> Option { @@ -220,3 +220,16 @@ impl TsAnyPropertyAnnotation { } } } + +impl JsAnyArrowFunctionParameters { + pub fn len(&self) -> usize { + match self { + JsAnyArrowFunctionParameters::JsAnyBinding(_) => 1, + JsAnyArrowFunctionParameters::JsParameters(parameters) => parameters.items().len(), + } + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } +} diff --git a/crates/rome_rowan/src/syntax/node.rs b/crates/rome_rowan/src/syntax/node.rs index c987dd63f36..471d00f0200 100644 --- a/crates/rome_rowan/src/syntax/node.rs +++ b/crates/rome_rowan/src/syntax/node.rs @@ -472,12 +472,32 @@ impl SyntaxNode { self.has_trailing_comments() || self.has_leading_comments() } + /// It checks if the current node has comments at the edges: + /// if first or last tokens contain comments (leading or trailing) + pub fn first_or_last_token_have_comments(&self) -> bool { + self.first_token_has_comments() || self.last_token_has_comments() + } + /// Whether the node contains trailing comments. pub fn has_trailing_comments(&self) -> bool { self.last_token() .map_or(false, |tok| tok.has_trailing_comments()) } + /// Whether the last token of a node has comments (leading or trailing) + pub fn last_token_has_comments(&self) -> bool { + self.last_token().map_or(false, |tok| { + tok.has_trailing_comments() || tok.has_leading_comments() + }) + } + + /// Whether the first token of a node has comments (leading or trailing) + pub fn first_token_has_comments(&self) -> bool { + self.first_token().map_or(false, |tok| { + tok.has_trailing_comments() || tok.has_leading_comments() + }) + } + /// Whether the node contains leading comments. pub fn has_leading_comments(&self) -> bool { self.first_token()