diff --git a/crates/rome_js_formatter/src/lib.rs b/crates/rome_js_formatter/src/lib.rs index a9b5ee8ab0ce..144905a775a8 100644 --- a/crates/rome_js_formatter/src/lib.rs +++ b/crates/rome_js_formatter/src/lib.rs @@ -750,11 +750,7 @@ function() { // use this test check if your snippet prints as you wish, without using a snapshot fn quick_test() { let src = r#" -type Example = { - [A in B]: T; -} & { - [A in B]: T; -}; + type C = B & (C | A) & B; "#; let syntax = SourceType::tsx(); diff --git a/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs b/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs index a9be1891e091..99aaf01b1d2e 100644 --- a/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs +++ b/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs @@ -1,5 +1,5 @@ -use crate::prelude::*; use crate::utils::should_hug_type; +use crate::{prelude::*, utils::is_object_like_type}; use rome_formatter::write; use rome_js_syntax::{ JsAnyExpression, JsSyntaxKind, JsVariableDeclarator, TsType, TsTypeArguments, @@ -28,10 +28,7 @@ impl FormatNodeRule for FormatTsTypeArguments { let first_argument = first_argument?; // first argument is not mapped type or object type - if !matches!( - first_argument, - TsType::TsObjectType(_) | TsType::TsMappedType(_) - ) { + if !is_object_like_type(&first_argument) { // we then go up until we can find a potential type annotation, // meaning four levels up let maybe_type_annotation = first_argument.syntax().ancestors().nth(4); diff --git a/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs b/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs index 56b3623079e1..bfdc942f11be 100644 --- a/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs @@ -1,6 +1,6 @@ -use crate::prelude::*; +use crate::{prelude::*, utils::is_object_like_type}; use rome_formatter::{format_args, write}; -use rome_js_syntax::{TsIntersectionTypeElementList, TsType}; +use rome_js_syntax::TsIntersectionTypeElementList; use rome_rowan::AstSeparatedList; #[derive(Debug, Clone, Default)] @@ -19,8 +19,7 @@ impl FormatRule for FormatTsIntersectionTypeEleme for (index, element) in node.elements().enumerate() { let node = element.node()?; - let is_object_type_like = - matches!(node, TsType::TsMappedType(_) | TsType::TsObjectType(_)); + let is_object_type_like = is_object_like_type(node); // always inline first element if index == 0 { diff --git a/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs b/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs index a1382bd16218..b466695e2353 100644 --- a/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs @@ -1,6 +1,7 @@ use crate::prelude::*; +use crate::utils::should_hug_type; use rome_formatter::write; -use rome_js_syntax::{JsLanguage, JsSyntaxKind, TsType, TsUnionTypeVariantList}; +use rome_js_syntax::{JsLanguage, TsType, TsUnionTypeVariantList}; use rome_rowan::{AstSeparatedElement, AstSeparatedList}; #[derive(Debug, Clone, Default)] @@ -10,15 +11,27 @@ impl FormatRule for FormatTsUnionTypeVariantList { type Context = JsFormatContext; fn fmt(&self, node: &TsUnionTypeVariantList, f: &mut JsFormatter) -> FormatResult<()> { + // ```ts + // { + // a: string + // } | null | void + // ``` + // should be inlined and not be printed in the multi-line variant + let should_hug = node + .parent::() + .as_ref() + .map_or(false, should_hug_type); + let last_index = node.len().saturating_sub(1); - f.join() + f.join_with(space()) .entries( node.elements() .enumerate() .map(|(index, item)| FormatTypeVariant { last: index == last_index, element: item, + should_hug, }), ) .finish() @@ -27,34 +40,30 @@ impl FormatRule for FormatTsUnionTypeVariantList { pub struct FormatTypeVariant { pub last: bool, + pub should_hug: bool, pub element: AstSeparatedElement, } impl Format for FormatTypeVariant { fn fmt(&self, f: &mut JsFormatter) -> FormatResult<()> { - write!(f, [group(&self.element.node().format())])?; - let separator = self.element.trailing_separator()?; - match separator { - Some(token) => { - if self.last { - write!(f, [format_removed(token)])?; + if self.should_hug { + write!(f, [self.element.node().format()])?; + } else { + write!(f, [align(2, &self.element.node().format())])?; + } + + if let Some(token) = separator { + if self.last { + write!(f, [format_removed(token)])?; + } else { + if self.should_hug { + write!(f, [space()])?; } else { - write![f, [soft_line_break_or_space(), token.format(), space()]]?; - } - } - None => { - if !self.last { - write![ - f, - [ - soft_line_break_or_space(), - format_inserted(JsSyntaxKind::PIPE), - space() - ] - ]?; + write!(f, [soft_line_break_or_space()])?; } + write![f, [token.format()]]?; } } diff --git a/crates/rome_js_formatter/src/ts/types/intersection_type.rs b/crates/rome_js_formatter/src/ts/types/intersection_type.rs index 47c7070c7874..94d9dbfddbe8 100644 --- a/crates/rome_js_formatter/src/ts/types/intersection_type.rs +++ b/crates/rome_js_formatter/src/ts/types/intersection_type.rs @@ -1,16 +1,12 @@ use crate::prelude::*; -use crate::parentheses::{ - is_in_many_type_union_or_intersection_list, operator_type_or_higher_needs_parens, - NeedsParentheses, +use crate::parentheses::NeedsParentheses; +use crate::utils::{ + union_or_intersection_type_needs_parentheses, FormatTypeMemberSeparator, + TsIntersectionOrUnionTypeList, }; -use crate::utils::FormatTypeMemberSeparator; use rome_formatter::{format_args, write}; -use rome_js_syntax::{ - JsSyntaxKind, JsSyntaxNode, TsIntersectionTypeElementList, TsIntersectionTypeFields, - TsUnionTypeVariantList, -}; -use rome_js_syntax::{JsSyntaxToken, TsIntersectionType}; +use rome_js_syntax::{JsSyntaxNode, TsIntersectionType, TsIntersectionTypeFields}; #[derive(Debug, Clone, Default)] pub struct FormatTsIntersectionType; @@ -35,28 +31,6 @@ impl FormatNodeRule for FormatTsIntersectionType { } } -pub struct FormatTypeSetLeadingSeparator<'a> { - pub(crate) separator: JsSyntaxKind, - pub(crate) leading_separator: Option<&'a JsSyntaxToken>, -} - -impl Format for FormatTypeSetLeadingSeparator<'_> { - fn fmt(&self, f: &mut JsFormatter) -> FormatResult<()> { - match &self.leading_separator { - Some(token) => { - format_only_if_breaks(token, &format_args!(token.format(), space())).fmt(f) - } - None => write!( - f, - [if_group_breaks(&format_args![ - format_inserted(self.separator), - space() - ])] - ), - } - } -} - impl NeedsParentheses for TsIntersectionType { fn needs_parentheses_with_parent(&self, parent: &JsSyntaxNode) -> bool { union_or_intersection_type_needs_parentheses( @@ -67,37 +41,6 @@ impl NeedsParentheses for TsIntersectionType { } } -pub(super) fn union_or_intersection_type_needs_parentheses( - node: &JsSyntaxNode, - parent: &JsSyntaxNode, - types: &TsIntersectionOrUnionTypeList, -) -> bool { - debug_assert!(matches!( - node.kind(), - JsSyntaxKind::TS_INTERSECTION_TYPE | JsSyntaxKind::TS_UNION_TYPE - )); - - if is_in_many_type_union_or_intersection_list(node, parent) { - types.len() > 1 - } else { - operator_type_or_higher_needs_parens(node, parent) - } -} - -pub(super) enum TsIntersectionOrUnionTypeList { - TsIntersectionTypeElementList(TsIntersectionTypeElementList), - TsUnionTypeVariantList(TsUnionTypeVariantList), -} - -impl TsIntersectionOrUnionTypeList { - fn len(&self) -> usize { - match self { - TsIntersectionOrUnionTypeList::TsIntersectionTypeElementList(list) => list.len(), - TsIntersectionOrUnionTypeList::TsUnionTypeVariantList(list) => list.len(), - } - } -} - #[cfg(test)] mod tests { diff --git a/crates/rome_js_formatter/src/ts/types/union_type.rs b/crates/rome_js_formatter/src/ts/types/union_type.rs index 6e20c2d25e58..8ab6cf8800ab 100644 --- a/crates/rome_js_formatter/src/ts/types/union_type.rs +++ b/crates/rome_js_formatter/src/ts/types/union_type.rs @@ -1,67 +1,110 @@ use crate::parentheses::NeedsParentheses; use crate::prelude::*; -use crate::ts::types::intersection_type::{ - union_or_intersection_type_needs_parentheses, FormatTypeSetLeadingSeparator, - TsIntersectionOrUnionTypeList, +use crate::utils::{ + has_leading_own_line_comment, should_hug_type, union_or_intersection_type_needs_parentheses, + FormatTypeMemberSeparator, TsIntersectionOrUnionTypeList, }; use rome_formatter::{format_args, write, Buffer}; -use rome_js_syntax::{JsSyntaxKind, TsUnionType}; +use rome_js_syntax::{JsSyntaxKind, JsSyntaxToken, TsTupleTypeElementList, TsUnionType}; use rome_js_syntax::{JsSyntaxNode, TsUnionTypeFields}; #[derive(Debug, Clone, Default)] pub struct FormatTsUnionType; impl FormatNodeRule for FormatTsUnionType { + // [Prettier applies]: https://github.com/prettier/prettier/blob/cd3e530c2e51fb8296c0fb7738a9afdd3a3a4410/src/language-js/print/type-annotation.js#L123-L202 fn fmt_fields(&self, node: &TsUnionType, f: &mut JsFormatter) -> FormatResult<()> { let TsUnionTypeFields { leading_separator_token, types, } = node.as_fields(); - let body = format_with(|f| { + // ```ts + // { + // a: string + // } | null | void + // ``` + // should be inlined and not be printed in the multi-line variant + if should_hug_type(&node.clone().into()) { + return write!( + f, + [ + FormatTypeMemberSeparator::new(leading_separator_token.as_ref()), + types.format() + ] + ); + } + + let has_leading_own_line_comment = has_leading_own_line_comment(node.syntax()); + + let should_indent = { + let parent_kind = node.syntax().parent().map(|p| p.kind()); + + // These parents have indent for their content, so we don't need to indent here + !match parent_kind { + Some(JsSyntaxKind::TS_TYPE_ALIAS_DECLARATION) => has_leading_own_line_comment, + parent_kind => { + matches!( + parent_kind, + Some( + JsSyntaxKind::TS_TYPE_ASSERTION_EXPRESSION + | JsSyntaxKind::TS_TUPLE_TYPE_ELEMENT_LIST + | JsSyntaxKind::TS_TYPE_ASSERTION_ASSIGNMENT + | JsSyntaxKind::TS_TYPE_ARGUMENT_LIST + ) + ) + } + } + }; + + let types = format_with(|f| { write!( f, [ - soft_line_break(), FormatTypeSetLeadingSeparator { separator: JsSyntaxKind::PIPE, - leading_separator: leading_separator_token.as_ref() + leading_separator: leading_separator_token.as_ref(), + leading_soft_line_break_or_space: should_indent + && !has_leading_own_line_comment, }, types.format() ] ) }); - if node.needs_parentheses() { - return write!(f, [group(&format_args![indent(&body), soft_line_break()])]); - } + let content = format_with(|f| { + // it is necessary to add parentheses for unions in intersections + // ```ts + // type Some = B & (C | A) & D + // ``` + if node.needs_parentheses() { + return write!(f, [indent(&types), soft_line_break()]); + } - let should_indent = { - let parent_kind = node.syntax().parent().map(|p| p.kind()); + let is_inside_complex_tuple_type = node + .parent::() + .map_or(false, |tuple| tuple.len() > 1); - !matches!( - parent_kind, - Some( - JsSyntaxKind::TS_REFERENCE_TYPE - | JsSyntaxKind::TS_TYPE_ASSERTION_EXPRESSION - | JsSyntaxKind::TS_TUPLE_TYPE - | JsSyntaxKind::TS_TYPE_ASSERTION_ASSIGNMENT - | JsSyntaxKind::TS_FUNCTION_TYPE - | JsSyntaxKind::TS_TYPE_ARGUMENTS + if is_inside_complex_tuple_type { + write!( + f, + [ + indent(&format_args![ + if_group_breaks(&format_args![text("("), soft_line_break()]), + types + ]), + soft_line_break(), + if_group_breaks(&text(")")) + ] ) - ) - }; + } else if should_indent { + write!(f, [&indent(&types)]) + } else { + write!(f, [&types]) + } + }); - write![ - f, - [group(&format_with(|f| { - if should_indent { - write!(f, [&indent(&body)]) - } else { - write!(f, [&body]) - } - }))] - ] + write!(f, [group(&content)]) } fn needs_parentheses(&self, item: &TsUnionType) -> bool { @@ -78,3 +121,35 @@ impl NeedsParentheses for TsUnionType { ) } } + +pub struct FormatTypeSetLeadingSeparator<'a> { + separator: JsSyntaxKind, + leading_separator: Option<&'a JsSyntaxToken>, + leading_soft_line_break_or_space: bool, +} + +impl Format for FormatTypeSetLeadingSeparator<'_> { + fn fmt(&self, f: &mut JsFormatter) -> FormatResult<()> { + match &self.leading_separator { + Some(token) => { + let content = format_with(|f| { + if self.leading_soft_line_break_or_space { + write!(f, [soft_line_break_or_space()])?; + } + write!(f, [token.format(), space()]) + }); + format_only_if_breaks(token, &content).fmt(f) + } + None => { + let content = format_with(|f| { + if self.leading_soft_line_break_or_space { + write!(f, [soft_line_break_or_space()])?; + } + write!(f, [format_inserted(self.separator), space()]) + }); + + write!(f, [if_group_breaks(&content)]) + } + } + } +} diff --git a/crates/rome_js_formatter/src/utils/assignment_like.rs b/crates/rome_js_formatter/src/utils/assignment_like.rs index 0b2f1ed37bb0..86faf3821ad8 100644 --- a/crates/rome_js_formatter/src/utils/assignment_like.rs +++ b/crates/rome_js_formatter/src/utils/assignment_like.rs @@ -5,6 +5,7 @@ use crate::utils::member_chain::is_member_call_chain; use crate::utils::object::write_member_name; use crate::utils::{JsAnyBinaryLikeExpression, JsAnyBinaryLikeLeftExpression}; use rome_formatter::{format_args, write, CstFormatContext, FormatOptions, VecBuffer}; +use rome_js_syntax::JsAnyLiteralExpression; use rome_js_syntax::{ JsAnyAssignmentPattern, JsAnyBindingPattern, JsAnyCallArgument, JsAnyClassMemberName, JsAnyExpression, JsAnyFunctionBody, JsAnyObjectAssignmentPatternMember, @@ -15,10 +16,11 @@ use rome_js_syntax::{ TsAnyVariableAnnotation, TsIdentifierBinding, TsPropertySignatureClassMember, TsPropertySignatureClassMemberFields, TsType, TsTypeAliasDeclaration, TsTypeArguments, }; -use rome_js_syntax::{JsAnyLiteralExpression, JsSyntaxNode}; use rome_rowan::{declare_node_union, AstNode, SyntaxResult}; use std::iter; +use super::has_leading_own_line_comment; + declare_node_union! { pub(crate) JsAnyAssignmentLike = JsPropertyObjectMember | @@ -874,34 +876,6 @@ pub(crate) fn should_break_after_operator(right: &JsAnyExpression) -> SyntaxResu Ok(result) } -/// Tests if the node has any leading comment that will be placed on its own line. -pub(crate) fn has_leading_own_line_comment(node: &JsSyntaxNode) -> bool { - if let Some(leading_trivia) = node.first_leading_trivia() { - let mut first_comment = true; - let mut after_comment = false; - let mut after_new_line = false; - - for piece in leading_trivia.pieces() { - if piece.is_comments() { - if after_new_line && first_comment { - return true; - } else { - first_comment = false; - after_comment = true; - } - } else if piece.is_newline() { - if after_comment { - return true; - } else { - after_new_line = true; - } - } else if piece.is_skipped() { - return false; - } - } - } - false -} impl Format for JsAnyAssignmentLike { fn fmt(&self, f: &mut JsFormatter) -> FormatResult<()> { diff --git a/crates/rome_js_formatter/src/utils/binary_like_expression.rs b/crates/rome_js_formatter/src/utils/binary_like_expression.rs index 5cafd52da47a..bc40af55320f 100644 --- a/crates/rome_js_formatter/src/utils/binary_like_expression.rs +++ b/crates/rome_js_formatter/src/utils/binary_like_expression.rs @@ -68,12 +68,13 @@ use crate::parentheses::{ }; use crate::js::expressions::static_member_expression::JsAnyStaticMemberLike; -use crate::utils::assignment_like::has_leading_own_line_comment; use rome_rowan::{declare_node_union, AstNode, SyntaxResult}; use std::fmt::Debug; use std::hash::Hash; use std::iter::FusedIterator; +use super::has_leading_own_line_comment; + declare_node_union! { pub(crate) JsAnyBinaryLikeExpression = JsLogicalExpression | JsBinaryExpression | JsInstanceofExpression | JsInExpression } diff --git a/crates/rome_js_formatter/src/utils/mod.rs b/crates/rome_js_formatter/src/utils/mod.rs index 9dbcf523b6ae..4403ea25e7ef 100644 --- a/crates/rome_js_formatter/src/utils/mod.rs +++ b/crates/rome_js_formatter/src/utils/mod.rs @@ -32,7 +32,10 @@ use rome_js_syntax::{JsAnyExpression, JsAnyStatement, JsInitializerClause, JsLan use rome_js_syntax::{JsSyntaxKind, JsSyntaxNode, JsSyntaxToken}; use rome_rowan::{AstNode, AstNodeList}; pub(crate) use string_utils::*; -pub(crate) use typescript::should_hug_type; +pub(crate) use typescript::{ + is_object_like_type, should_hug_type, union_or_intersection_type_needs_parentheses, + TsIntersectionOrUnionTypeList, +}; /// Utility function to format the separators of the nodes that belong to the unions /// of [rome_js_syntax::TsAnyTypeMember]. @@ -261,3 +264,32 @@ pub(crate) fn has_token_trailing_line_comment(token: &JsSyntaxToken) -> bool { .filter_map(|piece| piece.as_comments()) .any(|comment| JsCommentStyle.get_comment_kind(&comment).is_line()) } + +/// Tests if the node has any leading comment that will be placed on its own line. +pub(crate) fn has_leading_own_line_comment(node: &JsSyntaxNode) -> bool { + if let Some(leading_trivia) = node.first_leading_trivia() { + let mut first_comment = true; + let mut after_comment = false; + let mut after_new_line = false; + + for piece in leading_trivia.pieces() { + if piece.is_comments() { + if after_new_line && first_comment { + return true; + } else { + first_comment = false; + after_comment = true; + } + } else if piece.is_newline() { + if after_comment { + return true; + } else { + after_new_line = true; + } + } else if piece.is_skipped() { + return false; + } + } + } + false +} diff --git a/crates/rome_js_formatter/src/utils/typescript.rs b/crates/rome_js_formatter/src/utils/typescript.rs index b2f8264bf951..6ad20ab1760f 100644 --- a/crates/rome_js_formatter/src/utils/typescript.rs +++ b/crates/rome_js_formatter/src/utils/typescript.rs @@ -1,6 +1,23 @@ -use rome_js_syntax::TsType; +use rome_js_syntax::{ + JsSyntaxKind, JsSyntaxNode, TsIntersectionTypeElementList, TsType, TsUnionTypeVariantList, +}; use rome_rowan::AstSeparatedList; +use crate::parentheses::{ + is_in_many_type_union_or_intersection_list, operator_type_or_higher_needs_parens, +}; + +/// Utility function that checks if the current type is object like type +/// ```ts +/// type A = {}; +/// type B = { +/// [key in A]: number; +/// }; +/// ``` +pub(crate) fn is_object_like_type(ty: &TsType) -> bool { + matches!(ty, TsType::TsMappedType(_) | TsType::TsObjectType(_)) +} + /// Utility function that checks if the current type is can categorized as "simple" pub(crate) fn is_simple_type(ty: &TsType) -> bool { if matches!( @@ -38,7 +55,7 @@ pub(crate) fn is_simple_type(ty: &TsType) -> bool { /// /// [prettier]: https://github.com/prettier/prettier/blob/main/src/language-js/print/type-annotation.js#L27-L56 pub(crate) fn should_hug_type(ty: &TsType) -> bool { - if is_simple_type(ty) { + if is_simple_type(ty) || is_object_like_type(ty) { return true; } @@ -65,3 +82,34 @@ pub(crate) fn should_hug_type(ty: &TsType) -> bool { false } } + +pub(crate) fn union_or_intersection_type_needs_parentheses( + node: &JsSyntaxNode, + parent: &JsSyntaxNode, + types: &TsIntersectionOrUnionTypeList, +) -> bool { + debug_assert!(matches!( + node.kind(), + JsSyntaxKind::TS_INTERSECTION_TYPE | JsSyntaxKind::TS_UNION_TYPE + )); + + if is_in_many_type_union_or_intersection_list(node, parent) { + types.len() > 1 + } else { + operator_type_or_higher_needs_parens(node, parent) + } +} + +pub(crate) enum TsIntersectionOrUnionTypeList { + TsIntersectionTypeElementList(TsIntersectionTypeElementList), + TsUnionTypeVariantList(TsUnionTypeVariantList), +} + +impl TsIntersectionOrUnionTypeList { + fn len(&self) -> usize { + match self { + TsIntersectionOrUnionTypeList::TsIntersectionTypeElementList(list) => list.len(), + TsIntersectionOrUnionTypeList::TsUnionTypeVariantList(list) => list.len(), + } + } +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10846.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10846.ts.snap deleted file mode 100644 index 861b9f0d61ae..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10846.ts.snap +++ /dev/null @@ -1,139 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -const foo = call<{ - prop1: string; - prop2: string; - prop3: string; -}>(); - -export const CallRecorderContext = - createContext<{ - deleteRecording: (id: string) => void; - deleteAll: () => void; - } | null>(null); - -export const CallRecorderContext = - createContext<{ - deleteRecording: (id: string) => void; - deleteAll: () => void; - } | null>(null, "useless"); - -const foo = - call(); - -const foo = - call< - | Foooooooooooo - | Foooooooooooo - | Foooooooooooo - | Foooooooooooo - | Foooooooooooo - >(); - -const foo = - call< - Foooooooooooo & - Foooooooooooo & - Foooooooooooo & - Foooooooooooo & - Foooooooooooo - >(); -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,18 +1,24 @@ --const foo = call<{ -- prop1: string; -- prop2: string; -- prop3: string; --}>(); -+const foo = call< -+ { -+ prop1: string; -+ prop2: string; -+ prop3: string; -+ } -+>(); - --export const CallRecorderContext = createContext<{ -- deleteRecording: (id: string) => void; -- deleteAll: () => void; --} | null>(null); -+export const CallRecorderContext = createContext< -+ | { -+ deleteRecording: (id: string) => void; -+ deleteAll: () => void; -+ } -+ | null>(null); - --export const CallRecorderContext = createContext<{ -- deleteRecording: (id: string) => void; -- deleteAll: () => void; --} | null>(null, "useless"); -+export const CallRecorderContext = createContext< -+ | { -+ deleteRecording: (id: string) => void; -+ deleteAll: () => void; -+ } -+ | null>(null, "useless"); - - const foo = call< - Foooooo, -``` - -# Output - -```js -const foo = call< - { - prop1: string; - prop2: string; - prop3: string; - } ->(); - -export const CallRecorderContext = createContext< - | { - deleteRecording: (id: string) => void; - deleteAll: () => void; - } - | null>(null); - -export const CallRecorderContext = createContext< - | { - deleteRecording: (id: string) => void; - deleteAll: () => void; - } - | null>(null, "useless"); - -const foo = call< - Foooooo, - Foooooo, - Foooooo, - Foooooo, - Foooooo, - Foooooo, - Foooooo ->(); - -const foo = call< - Foooooooooooo | Foooooooooooo | Foooooooooooo | Foooooooooooo | Foooooooooooo ->(); - -const foo = call< - Foooooooooooo & Foooooooooooo & Foooooooooooo & Foooooooooooo & Foooooooooooo ->(); -``` - - - 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 deleted file mode 100644 index cedb16740b31..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-10848.tsx.snap +++ /dev/null @@ -1,177 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -const MyComponent: React.VoidFunctionComponent = ({ x }) => { - const a = useA() - return
x = {x}; a = {a}
-} - -const MyComponent2: React.VoidFunctionComponent = ({ x, y }) => { - const a = useA() - return
x = {x}; y = {y}; a = {a}
-} - -const MyComponentWithLongName1: React.VoidFunctionComponent = ({ x, y }) => { - const a = useA() - return
x = {x}; y = {y}; a = {a}
-} - -const MyComponentWithLongName2: React.VoidFunctionComponent = ({ x, y, anotherPropWithLongName1, anotherPropWithLongName2, anotherPropWithLongName3, anotherPropWithLongName4 }) => { - const a = useA() - return
x = {x}; y = {y}; a = {a}
-} - -const MyGenericComponent: React.VoidFunctionComponent> = ({ x, y }) => { - const a = useA() - return
x = {x}; y = {y}; a = {a}
-} - -export const ExportToExcalidrawPlus: React.FC<{ - elements: readonly NonDeletedExcalidrawElement[]; - appState: AppState; - onError: (error: Error) => void; -}> = ({ elements, appState, onError }) => { - return null; -} - -const Query: FunctionComponent = ({ - children, - type, - resource, - payload, - // Provides an undefined onSuccess just so the key `onSuccess` is defined - // This is used to detect options in useDataProvider - options = { onSuccess: undefined }, -}) => - children( - useQuery( - { type, resource, payload }, - { ...options, withDeclarativeSideEffectsSupport: true } - ) - ); -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -59,11 +59,13 @@ - ); - }; - --export const ExportToExcalidrawPlus: React.FC<{ -- elements: readonly NonDeletedExcalidrawElement[]; -- appState: AppState; -- onError: (error: Error) => void; --}> = ({ elements, appState, onError }) => { -+export const ExportToExcalidrawPlus: React.FC< -+ { -+ elements: readonly NonDeletedExcalidrawElement[]; -+ appState: AppState; -+ onError: (error: Error) => void; -+ } -+> = ({ elements, appState, onError }) => { - return null; - }; - -``` - -# Output - -```js -const MyComponent: React.VoidFunctionComponent = ({ x }) => { - const a = useA(); - return ( -
- x = {x}; a = {a} -
- ); -}; - -const MyComponent2: React.VoidFunctionComponent = ({ - x, - y, -}) => { - const a = useA(); - return ( -
- x = {x}; y = {y}; a = {a} -
- ); -}; - -const MyComponentWithLongName1: React.VoidFunctionComponent< - MyComponentWithLongNameProps -> = ({ x, y }) => { - const a = useA(); - return ( -
- x = {x}; y = {y}; a = {a} -
- ); -}; - -const MyComponentWithLongName2: React.VoidFunctionComponent< - MyComponentWithLongNameProps -> = ({ - x, - y, - anotherPropWithLongName1, - anotherPropWithLongName2, - anotherPropWithLongName3, - anotherPropWithLongName4, -}) => { - const a = useA(); - return ( -
- x = {x}; y = {y}; a = {a} -
- ); -}; - -const MyGenericComponent: React.VoidFunctionComponent< - MyGenericComponentProps -> = ({ x, y }) => { - const a = useA(); - return ( -
- x = {x}; y = {y}; a = {a} -
- ); -}; - -export const ExportToExcalidrawPlus: React.FC< - { - elements: readonly NonDeletedExcalidrawElement[]; - appState: AppState; - onError: (error: Error) => void; - } -> = ({ elements, appState, onError }) => { - return null; -}; - -const Query: FunctionComponent = ({ - children, - type, - resource, - payload, - // Provides an undefined onSuccess just so the key `onSuccess` is defined - // This is used to detect options in useDataProvider - options = { onSuccess: undefined }, -}) => - children( - useQuery( - { type, resource, payload }, - { ...options, withDeclarativeSideEffectsSupport: true }, - ), - ); -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-12413.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-12413.ts.snap deleted file mode 100644 index 6b054df402ce..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/issue-12413.ts.snap +++ /dev/null @@ -1,133 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -let emit = - defineEmits<{ (event: "ready", canvas: HTMLCanvasElement): void; (event:"resize",canvas:HTMLCanvasElement):void; }>(); - -let abc = - func<{a:2,b:3,d:78,e:9,f:8,g:7,h:6,i:5,j:4,k:3,l:2,m:1,n:0,o:9,p:8,q:7,r:6,s:5,t:4,u:3,v:2,w:1,x:0,y:9,z:8}>(); -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,32 +1,36 @@ --let emit = defineEmits<{ -- (event: "ready", canvas: HTMLCanvasElement): void; -- (event: "resize", canvas: HTMLCanvasElement): void; --}>(); -+let emit = defineEmits< -+ { -+ (event: "ready", canvas: HTMLCanvasElement): void; -+ (event: "resize", canvas: HTMLCanvasElement): void; -+ } -+>(); - --let abc = func<{ -- a: 2; -- b: 3; -- d: 78; -- e: 9; -- f: 8; -- g: 7; -- h: 6; -- i: 5; -- j: 4; -- k: 3; -- l: 2; -- m: 1; -- n: 0; -- o: 9; -- p: 8; -- q: 7; -- r: 6; -- s: 5; -- t: 4; -- u: 3; -- v: 2; -- w: 1; -- x: 0; -- y: 9; -- z: 8; --}>(); -+let abc = func< -+ { -+ a: 2; -+ b: 3; -+ d: 78; -+ e: 9; -+ f: 8; -+ g: 7; -+ h: 6; -+ i: 5; -+ j: 4; -+ k: 3; -+ l: 2; -+ m: 1; -+ n: 0; -+ o: 9; -+ p: 8; -+ q: 7; -+ r: 6; -+ s: 5; -+ t: 4; -+ u: 3; -+ v: 2; -+ w: 1; -+ x: 0; -+ y: 9; -+ z: 8; -+ } -+>(); -``` - -# Output - -```js -let emit = defineEmits< - { - (event: "ready", canvas: HTMLCanvasElement): void; - (event: "resize", canvas: HTMLCanvasElement): void; - } ->(); - -let abc = func< - { - a: 2; - b: 3; - d: 78; - e: 9; - f: 8; - g: 7; - h: 6; - i: 5; - j: 4; - k: 3; - l: 2; - m: 1; - n: 0; - o: 9; - p: 8; - q: 7; - r: 6; - s: 5; - t: 4; - u: 3; - v: 2; - w: 1; - x: 0; - y: 9; - z: 8; - } ->(); -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/generic-cast.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/generic-cast.ts.snap index 2427021a17eb..88a3c075048d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/generic-cast.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/cast/generic-cast.ts.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/cast/generic-cast.ts --- # Input @@ -80,30 +82,7 @@ function x() { const stillTooLong = < Immutable.Map< -@@ -24,37 +24,35 @@ - - const stillTooLong2 = < - | Immutable.Map< -- string, -- boolean, -- number, -- object, -- null, -- undefined, -- any, -- void, -- never -- > -+ string, -+ boolean, -+ number, -+ object, -+ null, -+ undefined, -+ any, -+ void, -+ never -+ > +@@ -37,10 +37,8 @@ | undefined >someExistingConfigMap.mergeDeep(fallbackOptions); @@ -116,30 +95,6 @@ function x() { ); const stillTooLong4 = < - | Immutable.Map< -- string, -- boolean, -- number, -- object, -- null, -- undefined, -- any, -- void, -- never -- > -+ string, -+ boolean, -+ number, -+ object, -+ null, -+ undefined, -+ any, -+ void, -+ never -+ > - | undefined - >someExistingConfigMap.mergeDeep( - fallbackOptions.someMethodWithLongName(param1, param2), @@ -111,9 +109,9 @@ const fitsObjLiteral = | undefined>{ a: "test" }; const fitsArrayLiteral = | undefined>["t1", "t2"]; @@ -201,16 +156,16 @@ function y() { const stillTooLong2 = < | Immutable.Map< - string, - boolean, - number, - object, - null, - undefined, - any, - void, - never - > + string, + boolean, + number, + object, + null, + undefined, + any, + void, + never + > | undefined >someExistingConfigMap.mergeDeep(fallbackOptions); @@ -220,16 +175,16 @@ function y() { const stillTooLong4 = < | Immutable.Map< - string, - boolean, - number, - object, - null, - undefined, - any, - void, - never - > + string, + boolean, + number, + object, + null, + undefined, + any, + void, + never + > | undefined >someExistingConfigMap.mergeDeep( fallbackOptions.someMethodWithLongName(param1, param2), diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/issues.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/issues.ts.snap deleted file mode 100644 index f8f6af983752..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/comments/issues.ts.snap +++ /dev/null @@ -1,146 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -// Adding a comment stops the pretty printing process and everything is -// squished in a single line afterward -export type BuckWebSocketMessage = { - // Not actually from Buck - this is to let the receiver know that the socket is connected. - type: 'SocketConnected', -} | { - type: 'BuildProgressUpdated', - progressValue: number, -} | { - type: 'BuildFinished', - exitCode: number, -} | { - type: 'BuildStarted', -} | { - type: 'ParseStarted', -} | { - type: 'ParseFinished', -} | { - type: 'RunStarted', -} | { - type: 'RunComplete', -}; - -// Two extra levels of indentation because of the comment -export type AsyncExecuteOptions = child_process$execFileOpts & { - // The contents to write to stdin. - stdin?: string, - dontLogInNuclide?: boolean, -}; -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -2,32 +2,32 @@ - // squished in a single line afterward - export type BuckWebSocketMessage = - | { -- // Not actually from Buck - this is to let the receiver know that the socket is connected. -- type: "SocketConnected"; -- } -+ // Not actually from Buck - this is to let the receiver know that the socket is connected. -+ type: "SocketConnected"; -+ } - | { -- type: "BuildProgressUpdated"; -- progressValue: number; -- } -+ type: "BuildProgressUpdated"; -+ progressValue: number; -+ } - | { -- type: "BuildFinished"; -- exitCode: number; -- } -+ type: "BuildFinished"; -+ exitCode: number; -+ } - | { -- type: "BuildStarted"; -- } -+ type: "BuildStarted"; -+ } - | { -- type: "ParseStarted"; -- } -+ type: "ParseStarted"; -+ } - | { -- type: "ParseFinished"; -- } -+ type: "ParseFinished"; -+ } - | { -- type: "RunStarted"; -- } -+ type: "RunStarted"; -+ } - | { -- type: "RunComplete"; -- }; -+ type: "RunComplete"; -+ }; - - // Two extra levels of indentation because of the comment - export type AsyncExecuteOptions = child_process$execFileOpts & { -``` - -# Output - -```js -// Adding a comment stops the pretty printing process and everything is -// squished in a single line afterward -export type BuckWebSocketMessage = - | { - // Not actually from Buck - this is to let the receiver know that the socket is connected. - type: "SocketConnected"; - } - | { - type: "BuildProgressUpdated"; - progressValue: number; - } - | { - type: "BuildFinished"; - exitCode: number; - } - | { - type: "BuildStarted"; - } - | { - type: "ParseStarted"; - } - | { - type: "ParseFinished"; - } - | { - type: "RunStarted"; - } - | { - type: "RunComplete"; - }; - -// Two extra levels of indentation because of the comment -export type AsyncExecuteOptions = child_process$execFileOpts & { - // The contents to write to stdin. - stdin?: string; - dontLogInNuclide?: boolean; -}; -``` - - -# Lines exceeding max width of 80 characters -``` - 5: // Not actually from Buck - this is to let the receiver know that the socket is connected. -``` - 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 9ba8cda15121..657861d47b12 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,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/custom/typeParameters/variables.ts --- # Input @@ -32,15 +34,13 @@ const fooooooooooooooo: SomeThing = looooooooooooooooooooooooo ```diff --- Prettier +++ Rome -@@ -1,18 +1,24 @@ +@@ -1,18 +1,20 @@ const foo: SomeThing = func(); const bar: SomeThing = func(); -const fooo: SomeThing<{ [P in "x" | "y"]: number }> = func(); -+const fooo: SomeThing< -+ { -+ [P in "x" | "y"]: number; -+ } -+> = func(); ++const fooo: SomeThing<{ ++ [P in "x" | "y"]: number; ++}> = func(); const baar: SomeThing = func(); const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); @@ -48,11 +48,9 @@ const fooooooooooooooo: SomeThing = looooooooooooooooooooooooo looooooooooooooooooooooooooooooongNameFunc(); -const baaaaaaaaaaaaaaar: SomeThing<{ [P in "x" | "y"]: number }> = - looooooooooooooooooooooooooooooongNameFunc(); -+const baaaaaaaaaaaaaaar: SomeThing< -+ { -+ [P in "x" | "y"]: number; -+ } -+> = looooooooooooooooooooooooooooooongNameFunc(); ++const baaaaaaaaaaaaaaar: SomeThing<{ ++ [P in "x" | "y"]: number; ++}> = looooooooooooooooooooooooooooooongNameFunc(); const baaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); -const isAnySuccessfulAttempt$: Observable = this._quizService @@ -70,21 +68,17 @@ const fooooooooooooooo: SomeThing = looooooooooooooooooooooooo ```js const foo: SomeThing = func(); const bar: SomeThing = func(); -const fooo: SomeThing< - { - [P in "x" | "y"]: number; - } -> = func(); +const fooo: SomeThing<{ + [P in "x" | "y"]: number; +}> = func(); const baar: SomeThing = func(); const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); const baaaaaaaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); -const baaaaaaaaaaaaaaar: SomeThing< - { - [P in "x" | "y"]: number; - } -> = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaar: SomeThing<{ + [P in "x" | "y"]: number; +}> = looooooooooooooooooooooooooooooongNameFunc(); const baaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); const isAnySuccessfulAttempt$: Observable = diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.snap index f642ee378779..5e13f16bc208 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/inlining.ts.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/union/inlining.ts --- # Input @@ -54,21 +56,8 @@ type T8 = number | (((((arg: any) => void)))); ```diff --- Prettier +++ Rome -@@ -2,13 +2,19 @@ - articles: a | null; - } - interface RelayProps { -- articles: Array<{ -- __id: string; -- } | null> | null | void; -+ articles: -+ | Array< -+ | { -+ __id: string; -+ } -+ | null> -+ | null -+ | void; +@@ -7,8 +7,9 @@ + } | null> | null | void; } -type UploadState = @@ -79,7 +68,7 @@ type T8 = number | (((((arg: any) => void)))); | { type: "Not_begun" } // The upload timed out | { type: "Timed_out" } -@@ -17,8 +23,9 @@ +@@ -17,8 +18,9 @@ // Uploading to aws3 and CreatePostMutation succeeded | { type: "Success"; data: D }; @@ -100,14 +89,9 @@ interface RelayProps { articles: a | null; } interface RelayProps { - articles: - | Array< - | { - __id: string; - } - | null> - | null - | void; + articles: Array<{ + __id: string; + } | null> | null | void; } type UploadState diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/prettier-ignore.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/prettier-ignore.ts.snap index a542fbd87285..17014fa8b062 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/prettier-ignore.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/prettier-ignore.ts.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/union/prettier-ignore.ts --- # Input @@ -38,40 +40,25 @@ export type a = ```diff --- Prettier +++ Rome -@@ -1,25 +1,25 @@ - export type a = -- // foo -- | (foo1 & foo2) -- // bar -- | (bar1 & bar2) -- // prettier-ignore +@@ -4,7 +4,7 @@ + // bar + | (bar1 & bar2) + // prettier-ignore - | qux1&qux2; -+ // foo -+ | (foo1 & foo2) -+ // bar -+ | (bar1 & bar2) -+ // prettier-ignore -+ | (qux1 & qux2); ++ | (qux1 & qux2); export type a = -- // foo -- | (foo1 & foo2) -- // bar -- | (bar1 & bar2) -- // prettier-ignore + // foo +@@ -12,7 +12,7 @@ + // bar + | (bar1 & bar2) + // prettier-ignore - | qux1&qux2 -- // baz -- | (baz1 & baz2); -+ // foo -+ | (foo1 & foo2) -+ // bar -+ | (bar1 & bar2) -+ // prettier-ignore -+ | (qux1 & qux2) -+ // baz -+ | (baz1 & baz2); ++ | (qux1 & qux2) + // baz + | (baz1 & baz2); - export type a = +@@ -20,6 +20,6 @@ // prettier-ignore | foo1&foo2 // bar @@ -86,22 +73,22 @@ export type a = ```js export type a = - // foo - | (foo1 & foo2) - // bar - | (bar1 & bar2) - // prettier-ignore - | (qux1 & qux2); + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | (qux1 & qux2); export type a = - // foo - | (foo1 & foo2) - // bar - | (bar1 & bar2) - // prettier-ignore - | (qux1 & qux2) - // baz - | (baz1 & baz2); + // foo + | (foo1 & foo2) + // bar + | (bar1 & bar2) + // prettier-ignore + | (qux1 & qux2) + // baz + | (baz1 & baz2); export type a = // prettier-ignore diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.snap deleted file mode 100644 index 13f96b17fbd3..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/union-parens.ts.snap +++ /dev/null @@ -1,260 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js - -export type A = ( - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb -); - -export type B = ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb -); - -export type C = - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - -export type D = - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - -export type Multi = (string | number)[]; - -function f(): (string | number) {} - -var x: (string | number); -var y: ((string | number)); - -class Foo {} - -interface Interface { - i: (X | Y) & Z; - j: Partial<(X | Y)>; -} - -type State = { - sharedProperty: any; -} & ( - | { discriminant: "FOO"; foo: any } - | { discriminant: "BAR"; bar: any } - | { discriminant: "BAZ"; baz: any } -); - -const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( - | string - | undefined -)[]; - -const foo2: ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD -)[] = []; - -const foo3: keyof ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD -) = bar; - -const foo4: - | foo - | ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD - ) = bar; - -let a1 : C; -let a2 : | C; -let a3 : (| C); -let a4 : | (C); -let a5 : (| (C)); -let a6 : /*1*/ | C; -let a7 : /*1*/ | (C); -let a8 : /*1*/ (| C); -let a9 : (/*1*/ | C); -let a10: /*1*/ | /*2*/ C; -let a11: /*1*/ (| /*2*/ C); - -let aa1: /*1*/ | /*2*/ C | D; -let aa2: /*1*/ | /*2*/ C | /*3*/ D; -let aa3: /*1*/ | /*2*/ C | /*3*/ D /*4*/; - -type A1 = C; -type A2 = | C; -type A3 = (| C); -type A4 = | (C); -type A5 = (| (C)); -type A6 = /*1*/ | C; -type A7 = /*1*/ | (C); -type A8 = /*1*/ (| C); -type A9 = (/*1*/ | C); -type A10 = /*1*/ | /*2*/ C; -type A11 = /*1*/ (| /*2*/ C); -type A12 = /*1*/ | ( (C)); -type A13 = /*1*/ ( (C)); - -type Aa1 = /*1*/ | /*2*/ C | D; -type Aa2 = /*1*/ | /*2*/ C | /*3*/ D; -type Aa3 = /*1*/ | /*2*/ C | /*3*/ D /*4*/; - -type C1 = /*1*/ & a | b; -type C2 = /*1*/ & a | (b); -type C3 = /*1*/ & a | (& b); -type C4 = /*1*/ & (a | b); -type C5 = /*1*/ (& a | b); -type C6 /*0*/ = /*1*/ (& a | b); - -type Ctor = (new () => X) | Y; -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -58,11 +58,11 @@ - const foo4: - | foo - | ( -- | AAAAAAAAAAAAAAAAAAAAAA -- | BBBBBBBBBBBBBBBBBBBBBB -- | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ) = bar; -+ | AAAAAAAAAAAAAAAAAAAAAA -+ | BBBBBBBBBBBBBBBBBBBBBB -+ | CCCCCCCCCCCCCCCCCCCCCC -+ | DDDDDDDDDDDDDDDDDDDDDD -+ ) = bar; - - let a1: C; - let a2: C; -``` - -# Output - -```js -export type A = - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - -export type B = - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - -export type C = - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - -export type D = - | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - -export type Multi = (string | number)[]; - -function f(): string | number {} - -var x: string | number; -var y: string | number; - -class Foo {} - -interface Interface { - i: (X | Y) & Z; - j: Partial; -} - -type State = { - sharedProperty: any; -} & ( - | { discriminant: "FOO"; foo: any } - | { discriminant: "BAR"; bar: any } - | { discriminant: "BAZ"; baz: any } -); - -const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( - | string - | undefined -)[]; - -const foo2: ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD -)[] = []; - -const foo3: keyof ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD -) = bar; - -const foo4: - | foo - | ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD - ) = bar; - -let a1: C; -let a2: C; -let a3: C; -let a4: C; -let a5: C; -let a6: /*1*/ C; -let a7: /*1*/ C; -let a8: /*1*/ C; -let a9: /*1*/ C; -let a10: /*1*/ /*2*/ C; -let a11: /*1*/ /*2*/ C; - -let aa1: /*1*/ /*2*/ C | D; -let aa2: /*1*/ /*2*/ C | /*3*/ D; -let aa3: /*1*/ /*2*/ C | /*3*/ D /*4*/; - -type A1 = C; -type A2 = C; -type A3 = C; -type A4 = C; -type A5 = C; -type A6 = /*1*/ C; -type A7 = /*1*/ C; -type A8 = /*1*/ C; -type A9 = /*1*/ C; -type A10 = /*1*/ /*2*/ C; -type A11 = /*1*/ /*2*/ C; -type A12 = /*1*/ C; -type A13 = /*1*/ C; - -type Aa1 = /*1*/ /*2*/ C | D; -type Aa2 = /*1*/ /*2*/ C | /*3*/ D; -type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; - -type C1 = /*1*/ a | b; -type C2 = /*1*/ a | b; -type C3 = /*1*/ a | b; -type C4 = /*1*/ a | b; -type C5 = /*1*/ a | b; -type C6 /*0*/ = /*1*/ a | b; - -type Ctor = (new () => X) | Y; -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/with-type-params.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/with-type-params.ts.snap deleted file mode 100644 index 706a7328d1b1..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/with-type-params.ts.snap +++ /dev/null @@ -1,49 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -type GetChatsSagaEffects = - | CallEffect - | PutEffect< - | GetUsersRequestedAction - | GetChatsSucceededAction - | GetChatsFailedAction - | GetChatsStartedAction - > - | SelectEffect -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -5,5 +5,5 @@ - | GetChatsSucceededAction - | GetChatsFailedAction - | GetChatsStartedAction -- > -+ > - | SelectEffect; -``` - -# Output - -```js -type GetChatsSagaEffects = - | CallEffect - | PutEffect< - | GetUsersRequestedAction - | GetChatsSucceededAction - | GetChatsFailedAction - | GetChatsStartedAction - > - | SelectEffect; -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/within-tuple.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/union/within-tuple.ts.snap deleted file mode 100644 index 373399d0cb82..000000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/union/within-tuple.ts.snap +++ /dev/null @@ -1,288 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] - -type B = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD -] - -type B1 = [ - ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD - ) -] - -type C = [ - | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] - | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] -] - -type D = [ - (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD), - (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD) -] - -type D1 = [ - ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD - ), - ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD - ) -] - -type D2 = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD -] - -type E = [ AA | BB, AA | BB ] - -type F = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB -] -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,92 +1,78 @@ - type A = [ -- | AAAAAAAAAAAAAAAAAAAAAA -- | BBBBBBBBBBBBBBBBBBBBBB -- | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD, -+ | AAAAAAAAAAAAAAAAAAAAAA -+ | BBBBBBBBBBBBBBBBBBBBBB -+ | CCCCCCCCCCCCCCCCCCCCCC -+ | DDDDDDDDDDDDDDDDDDDDDD, - ]; - - type B = [ -- | AAAAAAAAAAAAAAAAAAAAAA -- | BBBBBBBBBBBBBBBBBBBBBB -- | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD, -+ | AAAAAAAAAAAAAAAAAAAAAA -+ | BBBBBBBBBBBBBBBBBBBBBB -+ | CCCCCCCCCCCCCCCCCCCCCC -+ | DDDDDDDDDDDDDDDDDDDDDD, - ]; - - type B1 = [ -- | AAAAAAAAAAAAAAAAAAAAAA -- | BBBBBBBBBBBBBBBBBBBBBB -- | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD, -+ | AAAAAAAAAAAAAAAAAAAAAA -+ | BBBBBBBBBBBBBBBBBBBBBB -+ | CCCCCCCCCCCCCCCCCCCCCC -+ | DDDDDDDDDDDDDDDDDDDDDD, - ]; - - type C = [ -- | [ -- | AAAAAAAAAAAAAAAAAAAAAA -- | BBBBBBBBBBBBBBBBBBBBBB -- | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD, -+ | [ -+ | AAAAAAAAAAAAAAAAAAAAAA -+ | BBBBBBBBBBBBBBBBBBBBBB -+ | CCCCCCCCCCCCCCCCCCCCCC -+ | DDDDDDDDDDDDDDDDDDDDDD, - ] -- | [ -- | AAAAAAAAAAAAAAAAAAAAAA -- | BBBBBBBBBBBBBBBBBBBBBB -- | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD, -+ | [ -+ | AAAAAAAAAAAAAAAAAAAAAA -+ | BBBBBBBBBBBBBBBBBBBBBB -+ | CCCCCCCCCCCCCCCCCCCCCC -+ | DDDDDDDDDDDDDDDDDDDDDD, - ], - ]; - - type D = [ -- ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -- ( -+ | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -+ | DDDDDDDDDDDDDDDDDDDDDD, - ]; - - type D1 = [ -- ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -- ( -+ | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -+ | DDDDDDDDDDDDDDDDDDDDDD, - ]; - - type D2 = [ -- ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -- ( -+ | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -+ | DDDDDDDDDDDDDDDDDDDDDD, - ]; - - type E = [AA | BB, AA | BB]; - - type F = [ -- ( - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC -- | DDDDDDDDDDDDDDDDDDDDDD -- ), -+ | DDDDDDDDDDDDDDDDDDDDDD, - AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB, - ]; -``` - -# Output - -```js -type A = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, -]; - -type B = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, -]; - -type B1 = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, -]; - -type C = [ - | [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - ] - | [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - ], -]; - -type D = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, -]; - -type D1 = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, -]; - -type D2 = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, -]; - -type E = [AA | BB, AA | BB]; - -type F = [ - | AAAAAAAAAAAAAAAAAAAAAA - | BBBBBBBBBBBBBBBBBBBBBB - | CCCCCCCCCCCCCCCCCCCCCC - | DDDDDDDDDDDDDDDDDDDDDD, - AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB, -]; -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts b/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts index 28ef738cec34..b71ab3304140 100644 --- a/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts +++ b/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts @@ -2,7 +2,6 @@ type ShortUnion = | A | B - type LongUnion = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z type Comments = @@ -11,3 +10,237 @@ type Comments = // leading type A | B /* trailing type */ + +type A = [ + /*leading comment with new line*/ + A | B, + ]; + +type RemoveLeadingSeparatorIfNotBreak = /*a*/ | /*b*/ A | B; + +type BreakLongTypeAddedLeadingSeparator = BBBBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; +type BreakLongTypeWithLeadingComment = /*leading comment*/ BBBBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + + someLongLongObject.longlongmember; + + someLongLongObject.longlongmember; +( someLongLongObject.longlongmember) += 1 + +type FunctionTypeWithReturnUnion1 = () => /*1*/|/*2*/ A | B | C; + +type FunctionTypeWithReturnUnion2 = () => BBBBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +type InlineType = TypeName | null | void; +type InlineTypeWithLongName = TypeNameTypeNameTypeNameTypeNameTypeNameTypeNameTypeName | null | void; + +type TypeWithTypleInsideShort = [ + A | [A, B, C] | C, + A | [A, B, C] | C, + ]; + +type TypeWithTypleInsideLong = [ + AAAAAAAAAAAAAAAAA | [AAAAAAAAAAAAAAAAA, BBBBBBBBBBBB, CCCCCCCCCCCCC] | CCCCCCCCCCCCCCCCCCCC, + AAAAAAAAAAAAAAAAA | [AAAAAAAAAAAAAAAAA, BBBBBBBBBBBB, CCCCCCCCCCCCC] | CCCCCCCCCCCCCCCCCCCC, + ]; + +type TypeWithUnionInsideIntersactionAddParenthesesShort = B & (C | A) & D; + +type TypeWithUnionInsideIntersactionAddParenthesesLong = BBBBBBBBBBBB & (CCCCCCCCCCCCC | AAAAAAAAAAAAAAAAA) & DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +const fooo: SomeThingWithShortMappedType<{ + [P in A | B | C | string]: number; + }> = {}; + +const fooo: SomeThingWithLongMappedType<{ + [P in AAAAAAAAAAAAAAAAA | BBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD]: number; + }> = {}; + + export type A = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type B = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type C = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type D = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type Multi = (string | number)[]; + +function f(): string | number {} + +var x: string | number; +var y: string | number; + +class Foo {} + +interface Interface { + i: (X | Y) & Z; + j: Partial; +} + +type State = { + sharedProperty: any; +} & ( + | { discriminant: "FOO"; foo: any } + | { discriminant: "BAR"; bar: any } + | { discriminant: "BAZ"; baz: any } +); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1: C; +let a2: C; +let a3: C; +let a4: C; +let a5: C; +let a6: /*1*/ C; +let a7: /*1*/ C; +let a8: /*1*/ C; +let a9: /*1*/ C; +let a10: /*1*/ /*2*/ C; +let a11: /*1*/ /*2*/ C; + +let aa1: /*1*/ /*2*/ C | D; +let aa2: /*1*/ /*2*/ C | /*3*/ D; +let aa3: /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = C; +type A3 = C; +type A4 = C; +type A5 = C; +type A6 = /*1*/ C; +type A7 = /*1*/ C; +type A8 = /*1*/ C; +type A9 = /*1*/ C; +type A10 = /*1*/ /*2*/ C; +type A11 = /*1*/ /*2*/ C; +type A12 = /*1*/ C; +type A13 = /*1*/ C; + +type Aa1 = /*1*/ /*2*/ C | D; +type Aa2 = /*1*/ /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ a | b; +type C2 = /*1*/ a | b; +type C3 = /*1*/ a | b; +type C4 = /*1*/ a | b; +type C5 = /*1*/ a | b; +type C6 /*0*/ = /*1*/ a | b; + +type Ctor = (new () => X) | Y; + +type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type B1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type C = [ + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] +] + +type D = [ + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD), + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD) +] + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type D2 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type E = [ AA | BB, AA | BB ] + +type F = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB +] + +type GetChatsSagaEffects = + | CallEffect + | PutEffect< + | GetUsersRequestedAction + | GetChatsSucceededAction + | GetChatsFailedAction + | GetChatsStartedAction + > + | SelectEffect + +//https://github.com/prettier/prettier/issues/13153 +type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla = +| Fooo1000 +| Baz2000 +| BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong; \ No newline at end of file diff --git a/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts.snap b/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts.snap index 4ff0ef244e05..e6c57e353c0c 100644 --- a/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts.snap +++ b/crates/rome_js_formatter/tests/specs/ts/type/union_type.ts.snap @@ -7,7 +7,6 @@ type ShortUnion = | A | B - type LongUnion = A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z type Comments = @@ -17,6 +16,239 @@ type Comments = A | B /* trailing type */ +type A = [ + /*leading comment with new line*/ + A | B, + ]; + +type RemoveLeadingSeparatorIfNotBreak = /*a*/ | /*b*/ A | B; + +type BreakLongTypeAddedLeadingSeparator = BBBBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; +type BreakLongTypeWithLeadingComment = /*leading comment*/ BBBBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + + someLongLongObject.longlongmember; + + someLongLongObject.longlongmember; +( someLongLongObject.longlongmember) += 1 + +type FunctionTypeWithReturnUnion1 = () => /*1*/|/*2*/ A | B | C; + +type FunctionTypeWithReturnUnion2 = () => BBBBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +type InlineType = TypeName | null | void; +type InlineTypeWithLongName = TypeNameTypeNameTypeNameTypeNameTypeNameTypeNameTypeName | null | void; + +type TypeWithTypleInsideShort = [ + A | [A, B, C] | C, + A | [A, B, C] | C, + ]; + +type TypeWithTypleInsideLong = [ + AAAAAAAAAAAAAAAAA | [AAAAAAAAAAAAAAAAA, BBBBBBBBBBBB, CCCCCCCCCCCCC] | CCCCCCCCCCCCCCCCCCCC, + AAAAAAAAAAAAAAAAA | [AAAAAAAAAAAAAAAAA, BBBBBBBBBBBB, CCCCCCCCCCCCC] | CCCCCCCCCCCCCCCCCCCC, + ]; + +type TypeWithUnionInsideIntersactionAddParenthesesShort = B & (C | A) & D; + +type TypeWithUnionInsideIntersactionAddParenthesesLong = BBBBBBBBBBBB & (CCCCCCCCCCCCC | AAAAAAAAAAAAAAAAA) & DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +const fooo: SomeThingWithShortMappedType<{ + [P in A | B | C | string]: number; + }> = {}; + +const fooo: SomeThingWithLongMappedType<{ + [P in AAAAAAAAAAAAAAAAA | BBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD]: number; + }> = {}; + + export type A = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type B = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type C = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type D = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type Multi = (string | number)[]; + +function f(): string | number {} + +var x: string | number; +var y: string | number; + +class Foo {} + +interface Interface { + i: (X | Y) & Z; + j: Partial; +} + +type State = { + sharedProperty: any; +} & ( + | { discriminant: "FOO"; foo: any } + | { discriminant: "BAR"; bar: any } + | { discriminant: "BAZ"; baz: any } +); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1: C; +let a2: C; +let a3: C; +let a4: C; +let a5: C; +let a6: /*1*/ C; +let a7: /*1*/ C; +let a8: /*1*/ C; +let a9: /*1*/ C; +let a10: /*1*/ /*2*/ C; +let a11: /*1*/ /*2*/ C; + +let aa1: /*1*/ /*2*/ C | D; +let aa2: /*1*/ /*2*/ C | /*3*/ D; +let aa3: /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = C; +type A3 = C; +type A4 = C; +type A5 = C; +type A6 = /*1*/ C; +type A7 = /*1*/ C; +type A8 = /*1*/ C; +type A9 = /*1*/ C; +type A10 = /*1*/ /*2*/ C; +type A11 = /*1*/ /*2*/ C; +type A12 = /*1*/ C; +type A13 = /*1*/ C; + +type Aa1 = /*1*/ /*2*/ C | D; +type Aa2 = /*1*/ /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ a | b; +type C2 = /*1*/ a | b; +type C3 = /*1*/ a | b; +type C4 = /*1*/ a | b; +type C5 = /*1*/ a | b; +type C6 /*0*/ = /*1*/ a | b; + +type Ctor = (new () => X) | Y; + +type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type B1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type C = [ + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] +] + +type D = [ + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD), + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD) +] + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type D2 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type E = [ AA | BB, AA | BB ] + +type F = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB +] + +type GetChatsSagaEffects = + | CallEffect + | PutEffect< + | GetUsersRequestedAction + | GetChatsSucceededAction + | GetChatsFailedAction + | GetChatsStartedAction + > + | SelectEffect + +//https://github.com/prettier/prettier/issues/13153 +type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla = +| Fooo1000 +| Baz2000 +| BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong; ============================= # Outputs ## Output 1 @@ -57,10 +289,303 @@ type LongUnion = | Z; type Comments = - // leading separator - | - // leading type - A - | B /* + // leading separator + | + // leading type + A + | B /* trailing type */; +type A = [ + | + /*leading comment with new line*/ + A + | B, +]; + +type RemoveLeadingSeparatorIfNotBreak = /*a*/ /*b*/ A | B; + +type BreakLongTypeAddedLeadingSeparator = + | BBBBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; +type BreakLongTypeWithLeadingComment = /*leading comment*/ + | BBBBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +someLongLongObject.longlongmember; + +< + | BBBBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD +>someLongLongObject.longlongmember; +(< + | BBBBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD +>someLongLongObject.longlongmember) += 1; + +type FunctionTypeWithReturnUnion1 = () => /*1*/ /*2*/ A | B | C; + +type FunctionTypeWithReturnUnion2 = () => + | BBBBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +type InlineType = TypeName | null | void; +type InlineTypeWithLongName = + TypeNameTypeNameTypeNameTypeNameTypeNameTypeNameTypeName | null | void; + +type TypeWithTypleInsideShort = [A | [A, B, C] | C, A | [A, B, C] | C]; + +type TypeWithTypleInsideLong = [ + ( + | AAAAAAAAAAAAAAAAA + | [AAAAAAAAAAAAAAAAA, BBBBBBBBBBBB, CCCCCCCCCCCCC] + | CCCCCCCCCCCCCCCCCCCC + ), + ( + | AAAAAAAAAAAAAAAAA + | [AAAAAAAAAAAAAAAAA, BBBBBBBBBBBB, CCCCCCCCCCCCC] + | CCCCCCCCCCCCCCCCCCCC + ), +]; + +type TypeWithUnionInsideIntersactionAddParenthesesShort = B & (C | A) & D; + +type TypeWithUnionInsideIntersactionAddParenthesesLong = BBBBBBBBBBBB & + (CCCCCCCCCCCCC | AAAAAAAAAAAAAAAAA) & + DDDDDDDDDDDDDDDDDDDDDDDDDDDDD; + +const fooo: SomeThingWithShortMappedType<{ + [P in A | B | C | string]: number; +}> = {}; + +const fooo: SomeThingWithLongMappedType<{ + [P in + | AAAAAAAAAAAAAAAAA + | BBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDDDDDDDDD]: number; +}> = {}; + +export type A = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type B = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type C = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type D = + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +export type Multi = (string | number)[]; + +function f(): string | number {} + +var x: string | number; +var y: string | number; + +class Foo {} + +interface Interface { + i: (X | Y) & Z; + j: Partial; +} + +type State = { + sharedProperty: any; +} & ( + | { discriminant: "FOO"; foo: any } + | { discriminant: "BAR"; bar: any } + | { discriminant: "BAZ"; baz: any } +); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1: C; +let a2: C; +let a3: C; +let a4: C; +let a5: C; +let a6: /*1*/ C; +let a7: /*1*/ C; +let a8: /*1*/ C; +let a9: /*1*/ C; +let a10: /*1*/ /*2*/ C; +let a11: /*1*/ /*2*/ C; + +let aa1: /*1*/ /*2*/ C | D; +let aa2: /*1*/ /*2*/ C | /*3*/ D; +let aa3: /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = C; +type A3 = C; +type A4 = C; +type A5 = C; +type A6 = /*1*/ C; +type A7 = /*1*/ C; +type A8 = /*1*/ C; +type A9 = /*1*/ C; +type A10 = /*1*/ /*2*/ C; +type A11 = /*1*/ /*2*/ C; +type A12 = /*1*/ C; +type A13 = /*1*/ C; + +type Aa1 = /*1*/ /*2*/ C | D; +type Aa2 = /*1*/ /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ a | b; +type C2 = /*1*/ a | b; +type C3 = /*1*/ a | b; +type C4 = /*1*/ a | b; +type C5 = /*1*/ a | b; +type C6 /*0*/ = /*1*/ a | b; + +type Ctor = (new () => X) | Y; + +type A = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, +]; + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, +]; + +type B1 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, +]; + +type C = [ + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + ] + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + ], +]; + +type D = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), +]; + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), +]; + +type D2 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), +]; + +type E = [AA | BB, AA | BB]; + +type F = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB, +]; + +type GetChatsSagaEffects = + | CallEffect + | PutEffect< + | GetUsersRequestedAction + | GetChatsSucceededAction + | GetChatsFailedAction + | GetChatsStartedAction + > + | SelectEffect; + +//https://github.com/prettier/prettier/issues/13153 +type SuperLongTypeNameLoremIpsumLoremIpsumBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla = + | Fooo1000 + | Baz2000 + | BarLoooooooooooooooooooooooooooooooooooooooooooooooooLong; + diff --git a/npm/rome/src/index.ts b/npm/rome/src/index.ts index 3f4942e32c37..e97fc1f6f8b4 100644 --- a/npm/rome/src/index.ts +++ b/npm/rome/src/index.ts @@ -118,12 +118,12 @@ type Backend = NodeWasm | Deamon; export type RomeCreate = | { - backendKind: BackendKind.NODE; - } + backendKind: BackendKind.NODE; + } | { - backendKind: BackendKind.DAEMON; - pathToBinary?: string; - }; + backendKind: BackendKind.DAEMON; + pathToBinary?: string; + }; export class Rome { private readonly backend: Backend; diff --git a/website/playground/src/types.ts b/website/playground/src/types.ts index c40074ce3557..576434881219 100644 --- a/website/playground/src/types.ts +++ b/website/playground/src/types.ts @@ -72,14 +72,14 @@ export interface PlaygroundProps { export type PlaygroundSettings = Pick< PlaygroundState, - | "lineWidth" - | "indentWidth" - | "indentStyle" - | "quoteStyle" - | "quoteProperties" - | "sourceType" - | "isTypeScript" - | "isJsx" + | "lineWidth" + | "indentWidth" + | "indentStyle" + | "quoteStyle" + | "quoteProperties" + | "sourceType" + | "isTypeScript" + | "isJsx" >; export type Tree = ReturnType;