feat(rome_js_formatter): Member assignment formatting
MODIFY
crates/rome_js_formatter/src/js/assignments/computed_member_assignment.rs
crates/rome_js_formatter/src/js/assignments/computed_member_assignment.rs
use crate::prelude::*;
-use rome_formatter::write;
+use crate::js::expressions::computed_member_expression::JsAnyComputedMemberLike;
use rome_js_syntax::JsComputedMemberAssignment;
-use rome_js_syntax::JsComputedMemberAssignmentFields;
#[derive(Debug, Clone, Default)]
pub struct FormatJsComputedMemberAssignment;
@@ -13,21 +12,6 @@ impl FormatNodeRule<JsComputedMemberAssignment> for FormatJsComputedMemberAssign
node: &JsComputedMemberAssignment,
f: &mut JsFormatter,
) -> FormatResult<()> {
- let JsComputedMemberAssignmentFields {
- object,
- l_brack_token,
- member,
- r_brack_token,
- } = node.as_fields();
-
- write!(
- f,
- [
- object.format(),
- l_brack_token.format(),
- member.format(),
- r_brack_token.format(),
- ]
- )
+ JsAnyComputedMemberLike::from(node.clone()).fmt(f)
}
}

MODIFY
crates/rome_js_formatter/src/js/assignments/static_member_assignment.rs
crates/rome_js_formatter/src/js/assignments/static_member_assignment.rs
+use crate::js::expressions::static_member_expression::JsAnyStaticMemberLike;
use crate::prelude::*;
-use rome_formatter::write;
use rome_js_syntax::JsStaticMemberAssignment;
-use rome_js_syntax::JsStaticMemberAssignmentFields;
#[derive(Debug, Clone, Default)]
pub struct FormatJsStaticMemberAssignment;
impl FormatNodeRule<JsStaticMemberAssignment> for FormatJsStaticMemberAssignment {
fn fmt_fields(&self, node: &JsStaticMemberAssignment, f: &mut JsFormatter) -> FormatResult<()> {
- let JsStaticMemberAssignmentFields {
- object,
- dot_token,
- member,
- } = node.as_fields();
-
- write![f, [object.format(), dot_token.format(), member.format(),]]
+ JsAnyStaticMemberLike::from(node.clone()).fmt(f)
}
}

MODIFY
crates/rome_js_formatter/src/js/expressions/computed_member_expression.rs
crates/rome_js_formatter/src/js/expressions/computed_member_expression.rs
use crate::prelude::*;
use rome_formatter::{format_args, write};
-use rome_js_syntax::JsComputedMemberExpression;
-use rome_js_syntax::JsComputedMemberExpressionFields;
+use rome_js_syntax::JsSyntaxToken;
+use rome_js_syntax::{
+ JsAnyExpression, JsAnyLiteralExpression, JsComputedMemberAssignment, JsComputedMemberExpression,
+};
+use rome_rowan::{declare_node_union, SyntaxResult};
#[derive(Debug, Clone, Default)]
pub struct FormatJsComputedMemberExpression;
@@ -13,26 +16,91 @@ impl FormatNodeRule<JsComputedMemberExpression> for FormatJsComputedMemberExpres
node: &JsComputedMemberExpression,
f: &mut JsFormatter,
) -> FormatResult<()> {
- let JsComputedMemberExpressionFields {
- object,
- optional_chain_token,
- l_brack_token,
- member,
- r_brack_token,
- } = node.as_fields();
+ JsAnyComputedMemberLike::from(node.clone()).fmt(f)
+ }
+}
- write![
+declare_node_union! {
+ pub(crate) JsAnyComputedMemberLike = JsComputedMemberExpression | JsComputedMemberAssignment
+}
+
+impl Format<JsFormatContext> for JsAnyComputedMemberLike {
+ fn fmt(&self, f: &mut Formatter<JsFormatContext>) -> FormatResult<()> {
+ write!(f, [self.object().format()])?;
+
+ match self.member()? {
+ JsAnyExpression::JsAnyLiteralExpression(
+ JsAnyLiteralExpression::JsNumberLiteralExpression(literal),
+ ) => {
+ write!(
f,
[
- object.format(),
- group(&format_args![
- optional_chain_token.format(),
- l_brack_token.format(),
+ self.optional_chain_token().format(),
+ self.l_brack_token().format(),
+ literal.format(),
+ self.r_brack_token().format()
+ ]
+ )
+ }
+ member => {
+ write![
+ f,
+ [group(&format_args![
+ self.optional_chain_token().format(),
+ self.l_brack_token().format(),
soft_line_break(),
soft_block_indent(&member.format()),
- r_brack_token.format()
- ]),
- ]
+ self.r_brack_token().format()
+ ]),]
]
}
}
+ }
+}
+
+impl JsAnyComputedMemberLike {
+ fn object(&self) -> SyntaxResult<JsAnyExpression> {
+ match self {
+ JsAnyComputedMemberLike::JsComputedMemberExpression(expression) => expression.object(),
+ JsAnyComputedMemberLike::JsComputedMemberAssignment(assignment) => assignment.object(),
+ }
+ }
+
+ fn l_brack_token(&self) -> SyntaxResult<JsSyntaxToken> {
+ match self {
+ JsAnyComputedMemberLike::JsComputedMemberExpression(expression) => {
+ expression.l_brack_token()
+ }
+ JsAnyComputedMemberLike::JsComputedMemberAssignment(assignment) => {
+ assignment.l_brack_token()
+ }
+ }
+ }
+
+ fn optional_chain_token(&self) -> Option<JsSyntaxToken> {
+ match self {
+ JsAnyComputedMemberLike::JsComputedMemberExpression(expression) => {
+ expression.optional_chain_token()
+ }
+ JsAnyComputedMemberLike::JsComputedMemberAssignment(_) => None,
+ }
+ }
+
+ fn member(&self) -> SyntaxResult<JsAnyExpression> {
+ match self {
+ JsAnyComputedMemberLike::JsComputedMemberExpression(expression) => expression.member(),
+ JsAnyComputedMemberLike::JsComputedMemberAssignment(assignment) => assignment.member(),
+ }
+ }
+
+ fn r_brack_token(&self) -> SyntaxResult<JsSyntaxToken> {
+ match self {
+ JsAnyComputedMemberLike::JsComputedMemberExpression(expression) => {
+ expression.r_brack_token()
+ }
+ JsAnyComputedMemberLike::JsComputedMemberAssignment(assignment) => {
+ assignment.r_brack_token()
+ }
+ }
+ }
+}

MODIFY
crates/rome_js_formatter/src/js/expressions/static_member_expression.rs
crates/rome_js_formatter/src/js/expressions/static_member_expression.rs
use crate::prelude::*;
+use crate::js::expressions::computed_member_expression::JsAnyComputedMemberLike;
use rome_formatter::{format_args, write};
use rome_js_syntax::{
- JsAnyExpression, JsAssignmentExpression, JsStaticMemberExpression,
- JsStaticMemberExpressionFields, JsVariableDeclarator,
+ JsAnyAssignment, JsAnyAssignmentPattern, JsAnyExpression, JsAnyName, JsAssignmentExpression,
+ JsInitializerClause, JsStaticMemberAssignment, JsStaticMemberExpression, JsSyntaxToken,
};
-use rome_rowan::AstNode;
+use rome_rowan::{declare_node_union, AstNode, SyntaxResult};
#[derive(Debug, Clone, Default)]
pub struct FormatJsStaticMemberExpression;
impl FormatNodeRule<JsStaticMemberExpression> for FormatJsStaticMemberExpression {
fn fmt_fields(&self, node: &JsStaticMemberExpression, f: &mut JsFormatter) -> FormatResult<()> {
- let JsStaticMemberExpressionFields {
- object,
- operator_token,
- member,
- } = node.as_fields();
+ JsAnyStaticMemberLike::from(node.clone()).fmt(f)
+ }
+}
+
+#[derive(Debug, Copy, Clone)]
+enum StaticMemberLikeLayout {
+ /// Forces that there's no line break between the object, operator, and member
+ NoBreak,
+
+ /// Breaks the static member expression after the object if the whole expression doesn't fit on a single line
+ BreakAfterObject,
+}
+
+declare_node_union! {
+ pub(crate) JsAnyStaticMemberLike = JsStaticMemberExpression | JsStaticMemberAssignment
+}
- write!(f, [object.format()])?;
+impl Format<JsFormatContext> for JsAnyStaticMemberLike {
+ fn fmt(&self, f: &mut Formatter<JsFormatContext>) -> FormatResult<()> {
+ write!(f, [self.object().format()])?;
- let layout = compute_member_layout(node)?;
+ let layout = self.layout()?;
match layout {
- StaticMemberExpressionLayout::NoBreak => {
- write!(f, [operator_token.format(), member.format()])
+ StaticMemberLikeLayout::NoBreak => {
+ write!(f, [self.operator_token().format(), self.member().format()])
}
- StaticMemberExpressionLayout::BreakAfterObject => {
+ StaticMemberLikeLayout::BreakAfterObject => {
write!(
f,
[group(&indent(&format_args![
soft_line_break(),
- operator_token.format(),
- member.format(),
+ self.operator_token().format(),
+ self.member().format(),
]))]
)
}
@@ -40,28 +54,40 @@ impl FormatNodeRule<JsStaticMemberExpression> for FormatJsStaticMemberExpression
}
}
-enum StaticMemberExpressionLayout {
- /// Forces that there's no line break between the object, operator, and member
- NoBreak,
+impl JsAnyStaticMemberLike {
+ fn object(&self) -> SyntaxResult<JsAnyExpression> {
+ match self {
+ JsAnyStaticMemberLike::JsStaticMemberExpression(expression) => expression.object(),
+ JsAnyStaticMemberLike::JsStaticMemberAssignment(assignment) => assignment.object(),
+ }
+ }
- /// Breaks the static member expression after the object if the whole expression doesn't fit on a single line
- BreakAfterObject,
+ fn operator_token(&self) -> SyntaxResult<JsSyntaxToken> {
+ match self {
+ JsAnyStaticMemberLike::JsStaticMemberExpression(expression) => {
+ expression.operator_token()
+ }
+ JsAnyStaticMemberLike::JsStaticMemberAssignment(assignment) => assignment.dot_token(),
+ }
}
-fn compute_member_layout(
- member: &JsStaticMemberExpression,
-) -> FormatResult<StaticMemberExpressionLayout> {
- let parent = member.syntax().parent();
+ fn member(&self) -> SyntaxResult<JsAnyName> {
+ match self {
+ JsAnyStaticMemberLike::JsStaticMemberExpression(expression) => expression.member(),
+ JsAnyStaticMemberLike::JsStaticMemberAssignment(assignment) => assignment.member(),
+ }
+ }
- let nested = parent
- .as_ref()
- .map_or(false, |p| JsStaticMemberExpression::can_cast(p.kind()));
+ fn layout(&self) -> SyntaxResult<StaticMemberLikeLayout> {
+ let parent = self.syntax().parent();
+ let object = self.object()?;
- if let Some(parent) = &parent {
+ let is_nested = match &parent {
+ Some(parent) => {
if JsAssignmentExpression::can_cast(parent.kind())
- || JsVariableDeclarator::can_cast(parent.kind())
+ || JsInitializerClause::can_cast(parent.kind())
{
- let no_break = match member.object()? {
+ let no_break = match &object {
JsAnyExpression::JsCallExpression(call_expression) => {
!call_expression.arguments()?.args().is_empty()
}
@@ -77,26 +103,42 @@ fn compute_member_layout(
};
if no_break {
- return Ok(StaticMemberExpressionLayout::NoBreak);
+ return Ok(StaticMemberLikeLayout::NoBreak);
}
}
+
+ JsAnyStaticMemberLike::can_cast(parent.kind())
+ || JsAnyComputedMemberLike::can_cast(parent.kind())
+ }
+ None => false,
};
- if !nested && matches!(member.object()?, JsAnyExpression::JsIdentifierExpression(_)) {
- return Ok(StaticMemberExpressionLayout::NoBreak);
+ if !is_nested && matches!(&object, JsAnyExpression::JsIdentifierExpression(_)) {
+ return Ok(StaticMemberLikeLayout::NoBreak);
}
- let first_non_static_member_ancestor = member
- .syntax()
- .ancestors()
- .find(|parent| !JsStaticMemberExpression::can_cast(parent.kind()));
+ let first_non_static_member_ancestor = self.syntax().ancestors().find(|parent| {
+ !JsAnyStaticMemberLike::can_cast(parent.kind())
+ || JsAnyComputedMemberLike::can_cast(parent.kind())
+ });
+ let layout = match first_non_static_member_ancestor.and_then(JsAnyExpression::cast) {
+ Some(JsAnyExpression::JsNewExpression(_)) => StaticMemberLikeLayout::NoBreak,
+ Some(JsAnyExpression::JsAssignmentExpression(assignment)) => {
if matches!(
- first_non_static_member_ancestor.and_then(JsAnyExpression::cast),
- Some(JsAnyExpression::JsNewExpression(_))
+ assignment.left()?,
+ JsAnyAssignmentPattern::JsAnyAssignment(
+ JsAnyAssignment::JsIdentifierAssignment(_)
+ )
) {
- return Ok(StaticMemberExpressionLayout::NoBreak);
+ StaticMemberLikeLayout::BreakAfterObject
+ } else {
+ StaticMemberLikeLayout::NoBreak
}
+ }
+ _ => StaticMemberLikeLayout::BreakAfterObject,
+ };
- Ok(StaticMemberExpressionLayout::BreakAfterObject)
+ Ok(layout)
+ }
}

MODIFY
crates/rome_js_formatter/tests/specs/js/module/declarations/variable_declaration.js.snap
crates/rome_js_formatter/tests/specs/js/module/declarations/variable_declaration.js.snap
@@ -382,8 +382,9 @@ var loooooooooooooooooooooooooong1 =
aaaaaaaaaaaaaaaaaaaa,
);
let loooooooooooooooooooooooooong2 =
- objdddddddddectobjdddddddddect(aaaaaaaaaaaaaaaaaaaa)
- .ewqeqewqweqweqweqweqweqweqw;
+ objdddddddddectobjdddddddddect(
+ aaaaaaaaaaaaaaaaaaaa,
+ ).ewqeqewqweqweqweqweqweqweqw;
let loooooooooooooooooooooooooong3 =
objdddddddddectobjdddddddddect(aaaaaaaaaaaaaaaaaaaa)[dsadsadsadsadsadsadsa]()
.ewqoewqoeiowqieopwqie;
@@ -397,8 +398,9 @@ var loooooooooooooooooooooooooong1 =
+12312312321321312,
);
let loooooooooooooooooooooooooong2 =
- objdddddddddectobjdddddddddect(-12312312321321312)
- .ewqeqewqweqweqweqweqweqweqw;
+ objdddddddddectobjdddddddddect(
+ -12312312321321312,
+ ).ewqeqewqweqweqweqweqweqweqw;
//JsStringLiteralExpression argument
var loooooooooooooooooooooooooong1 =
@@ -406,8 +408,9 @@ var loooooooooooooooooooooooooong1 =
"111111111111111111",
);
let loooooooooooooooooooooooooong2 =
- objdddddddddectobjdddddddddect("111111111111111111")
- .ewqeqewqweqweqweqweqweqweqw;
+ objdddddddddectobjdddddddddect(
+ "111111111111111111",
+ ).ewqeqewqweqweqweqweqweqweqw;
let loooooooooooooooooooooooooong3 =
objdddddddddectobjdddddddddect("111111111111111111")[dsadsadsadsadsadsadsa]()
.ewqoewqoeiowqieopwqie;
@@ -419,8 +422,9 @@ let loooooooooooooooooooooooooong3 =
var loooooooooooooooooooooooooong1 =
objdddddddddectobjdddddddddect(/\wwwwwwwwwwwwwwwwww+/gi);
let loooooooooooooooooooooooooong2 =
- objdddddddddectobjdddddddddect(/\wwwwwwwwwwwwwwwwww+/gi)
- .ewqeqewqweqweqweqweqweqweqw;
+ objdddddddddectobjdddddddddect(
+ /\wwwwwwwwwwwwwwwwww+/gi,
+ ).ewqeqewqweqweqweqweqweqweqw;
let loooooooooooooooooooooooooong3 =
objdddddddddectobjdddddddddect(
/\wwwwwwwwwwwwwwwwww+/gi,
@@ -436,8 +440,9 @@ var loooooooooooooooooooooooooong1 =
``,
);
let loooooooooooooooooooooooooong2 =
- objdddddddddectobjdddsadsadddddddect(`111111111111111111`)
- .ewqeqewqweqweqweqweqweqweqw;
+ objdddddddddectobjdddsadsadddddddect(
+ `111111111111111111`,
+ ).ewqeqewqweqweqweqweqweqweqw;
let loooooooooooooooooooooooooong3 =
objdddddddddectobjddsadsaddddddddect(
`111111111111111111`,
@@ -453,8 +458,9 @@ var loooooooooooooooooooooooooong1 =
true,
);
let loooooooooooooooooooooooooong2 =
- objdddddddddectobjdddddddsadsadasdddect(undefined)
- .ewqeqewqweqweqweqweqweqweqw;
+ objdddddddddectobjdddddddsadsadasdddect(
+ undefined,
+ ).ewqeqewqweqweqweqweqweqweqw;
let loooooooooooooooooooooooooong3 =
objdddddddddectobjdddddddddect(321321312321312321321)[dsadsadsadsadsadsadsa]()
.ewqoewqoeiowqieopwqie;
@@ -530,8 +536,9 @@ let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
this(9007199254740991n)[dsadsadsadsadsadsadsa]().ewqoewqoeiowqieopwqie;
//fluid layout
-const otherBrandsWithThisAdjacencyCount123 = Object.values(edge.to.edges)
- .length;
+const otherBrandsWithThisAdjacencyCount123 = Object.values(
+ edge.to.edges,
+).length;
let vgChannel = pointPositionDefaultRef({ model, defaultPos, channel })();
const bifornCringerMoshedPerplexSawderGlyphsHb = someBigFunctionName(
`foo
@@ -742,56 +749,56 @@ const a
78: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
80: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
82: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong5 =
- 188: var looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 190: let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 192: let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 194: let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 198: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 200: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 202: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 204: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 208: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 210: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 194: var looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 196: let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 198: let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 200: let looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 204: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 206: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 208: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 210: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
214: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
216: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 218: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 220: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 224: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 226: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 228: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 230: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 234: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 236: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 238: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 240: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 244: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 246: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 248: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 250: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 361: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 363: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 365: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 369: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 371: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 373: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 375: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 379: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 381: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 383: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 385: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 389: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 391: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 393: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 396: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
- 401: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 403: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 405: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 410: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 412: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 414: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 418: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 423: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
- 428: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
- 444: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
- 446: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 220: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 222: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 224: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 226: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 230: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 232: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 234: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 236: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 240: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 242: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 244: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 246: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 250: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 252: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 254: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 256: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 368: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 370: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 372: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 376: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 378: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 380: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 382: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 386: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 388: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 390: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 392: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 396: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 398: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 400: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 403: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong4 =
+ 408: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 410: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 412: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 417: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 419: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 421: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 425: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 430: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =
+ 435: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong3 =
+ 451: var loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
+ 453: let loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2 =

MODIFY
crates/rome_js_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap
crates/rome_js_formatter/tests/specs/js/module/expression/import_meta_expression/import_meta_expression.js.snap
@@ -17,10 +17,14 @@ Quote style: Double Quotes
-----
console.log(import.meta);
import.meta.field =
- obj.aReallyLongVariableName.andAnotherReallyLongVariableName
- .andAnotherReallyLongVariableName.andAnotherReallyLongVariable;
+ obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable;
import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName
.andAnotherReallyLongVariableName.andAnotherReallyLongVariable;
+
+
+## Lines exceeding width of 80 characters
+
+ 3: obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable;
## Output 2
-----
Indent style: Spaces, size: 4
@@ -29,8 +33,12 @@ Quote style: Double Quotes
-----
console.log(import.meta);
import.meta.field =
- obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName
- .andAnotherReallyLongVariable;
+ obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable;
import.meta.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName
.andAnotherReallyLongVariable;
+
+## Lines exceeding width of 120 characters
+
+ 3: obj.aReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariableName.andAnotherReallyLongVariable;
+

DELETE
crates/rome_js_formatter/tests/specs/prettier/js/assignment/issue-1966.js.snap
----
-source: crates/rome_js_formatter/tests/prettier_tests.rs
----
-
-# Input
-
-```js
-const aVeryLongNameThatGoesOnAndOn = this.someOtherObject.someOtherNestedObject.someLongFunctionName();
-
-this.someObject.someOtherNestedObject = this.someOtherObject.whyNotNestAnotherOne.someLongFunctionName();
-
-this.isaverylongmethodexpression.withmultiplelevels = this.isanotherverylongexpression.thatisalsoassigned = 0;
-```
-
-
-# Prettier differences
-
-```diff
---- Prettier
-+++ Rome
-@@ -4,5 +4,5 @@
- this.someObject.someOtherNestedObject =
- this.someOtherObject.whyNotNestAnotherOne.someLongFunctionName();
-
--this.isaverylongmethodexpression.withmultiplelevels =
-- this.isanotherverylongexpression.thatisalsoassigned = 0;
-+this.isaverylongmethodexpression.withmultiplelevels = this
-+ .isanotherverylongexpression.thatisalsoassigned = 0;
-```
-
-# Output
-
-```js
-const aVeryLongNameThatGoesOnAndOn =
- this.someOtherObject.someOtherNestedObject.someLongFunctionName();
-
-this.someObject.someOtherNestedObject =
- this.someOtherObject.whyNotNestAnotherOne.someLongFunctionName();
-
-this.isaverylongmethodexpression.withmultiplelevels = this
- .isanotherverylongexpression.thatisalsoassigned = 0;
-```
-
-
-

DELETE
crates/rome_js_formatter/tests/specs/prettier/js/assignment/issue-4094.js.snap
----
-source: crates/rome_js_formatter/tests/prettier_tests.rs
----
-
-# Input
-
-```js
-if (something) {
- const otherBrandsWithThisAdjacencyCount123 = Object.values(edge.to.edges).length
-}
-```
-
-
-# Prettier differences
-
-```diff
---- Prettier
-+++ Rome
-@@ -1,5 +1,4 @@
- if (something) {
-- const otherBrandsWithThisAdjacencyCount123 = Object.values(
-- edge.to.edges,
-- ).length;
-+ const otherBrandsWithThisAdjacencyCount123 = Object.values(edge.to.edges)
-+ .length;
- }
-```
-
-# Output
-
-```js
-if (something) {
- const otherBrandsWithThisAdjacencyCount123 = Object.values(edge.to.edges)
- .length;
-}
-```
-
-
-

MODIFY
crates/rome_js_formatter/tests/specs/prettier/js/classes/assignment.js.snap
crates/rome_js_formatter/tests/specs/prettier/js/classes/assignment.js.snap
@@ -44,22 +44,14 @@ module.exports = class A extends B {
```diff
--- Prettier
+++ Rome
-@@ -1,4 +1,5 @@
--aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends (
-+aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee
-+ .ffffffff.gggggggg2 = class extends (
- aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg1
- ) {
- method() {
-@@ -12,17 +13,15 @@
+@@ -12,17 +12,14 @@
}
};
-aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends (
- bar
-) {
-+aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee
-+ .ffffffff.gggggggg2 = class extends bar {
++aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends bar {
method() {
console.log("foo");
}
@@ -78,8 +70,7 @@ module.exports = class A extends B {
# Output
```js
-aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee
- .ffffffff.gggggggg2 = class extends (
+aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends (
aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg1
) {
method() {
@@ -93,8 +84,7 @@ foo = class extends bar {
}
};
-aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee
- .ffffffff.gggggggg2 = class extends bar {
+aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends bar {
method() {
console.log("foo");
}
@@ -115,4 +105,9 @@ module.exports = class A extends B {
```
+# Lines exceeding max width of 80 characters
+```
+ 1: aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends (
+ 15: aaaaaaaa.bbbbbbbb.cccccccc.dddddddd.eeeeeeee.ffffffff.gggggggg2 = class extends bar {
+```

DELETE
crates/rome_js_formatter/tests/specs/prettier/js/method-chain/bracket_0.js.snap
----
-source: crates/rome_js_formatter/tests/prettier_tests.rs
----
-
-# Input
-
-```js
-function a() {
- function b() {
- queryThenMutateDOM(
- () => {
- title = SomeThing.call(root, 'someLongStringThatPushesThisTextReallyFar')[0];
- }
- );
- }
-}
-```
-
-
-# Prettier differences
-
-```diff
---- Prettier
-+++ Rome
-@@ -1,10 +1,9 @@
- function a() {
- function b() {
- queryThenMutateDOM(() => {
-- title = SomeThing.call(
-- root,
-- "someLongStringThatPushesThisTextReallyFar",
-- )[0];
-+ title = SomeThing.call(root, "someLongStringThatPushesThisTextReallyFar")[
-+ 0
-+ ];
- });
- }
- }
-```
-
-# Output
-
-```js
-function a() {
- function b() {
- queryThenMutateDOM(() => {
- title = SomeThing.call(root, "someLongStringThatPushesThisTextReallyFar")[
- 0
- ];
- });
- }
-}
-```
-
-
-

MODIFY
crates/rome_js_formatter/tests/specs/prettier/js/method-chain/break-last-member.js.snap
crates/rome_js_formatter/tests/specs/prettier/js/method-chain/break-last-member.js.snap
@@ -33,18 +33,7 @@ const {
```diff
--- Prettier
+++ Rome
-@@ -3,22 +3,17 @@
- weNeedToReachTheEightyCharacterLimitXXXXXXXXXXXXXXXXX.someNode
- .childrenInAnArray[0];
- superSupersuperSupersuperSupersuperSupersuperSuperLong.exampleOfOrderOfGetterAndSetterReordered;
--superSupersuperSupersuperSupersuperSupersuperSuperLong
-- .exampleOfOrderOfGetterAndSetterReordered[0];
-+superSupersuperSupersuperSupersuperSupersuperSuperLong.exampleOfOrderOfGetterAndSetterReordered[
-+ 0
-+];
-
- expect(
- findDOMNode(component.instance()).getElementsByClassName(styles.inner)[0]
+@@ -11,14 +11,8 @@
.style.paddingRight,
).toBe("1000px");
@@ -71,9 +60,8 @@ SomeVeryLongUpperCaseConstant.someVeryLongCallExpression()
weNeedToReachTheEightyCharacterLimitXXXXXXXXXXXXXXXXX.someNode
.childrenInAnArray[0];
superSupersuperSupersuperSupersuperSupersuperSuperLong.exampleOfOrderOfGetterAndSetterReordered;
-superSupersuperSupersuperSupersuperSupersuperSuperLong.exampleOfOrderOfGetterAndSetterReordered[
- 0
-];
+superSupersuperSupersuperSupersuperSupersuperSuperLong
+ .exampleOfOrderOfGetterAndSetterReordered[0];
expect(
findDOMNode(component.instance()).getElementsByClassName(styles.inner)[0]
@@ -104,6 +92,5 @@ const {
# Lines exceeding max width of 80 characters
```
5: superSupersuperSupersuperSupersuperSupersuperSuperLong.exampleOfOrderOfGetterAndSetterReordered;
- 6: superSupersuperSupersuperSupersuperSupersuperSuperLong.exampleOfOrderOfGetterAndSetterReordered[
```

DELETE
crates/rome_js_formatter/tests/specs/prettier/typescript/assignment/lone-arg.ts.snap
----
-source: crates/rome_js_formatter/tests/prettier_tests.rs
----
-
-# Input
-
-```js
-if (true) {
- if (condition) {
- const secondType = sourceCode.getNodeByRangeIndex1234(second.range[0])!
- .type;
- }
-}
-```
-
-
-# Prettier differences
-
-```diff
---- Prettier
-+++ Rome
-@@ -1,7 +1,6 @@
- if (true) {
- if (condition) {
-- const secondType = sourceCode.getNodeByRangeIndex1234(
-- second.range[0],
-- )!.type;
-+ const secondType = sourceCode.getNodeByRangeIndex1234(second.range[0])!
-+ .type;
- }
- }
-```
-
-# Output
-
-```js
-if (true) {
- if (condition) {
- const secondType = sourceCode.getNodeByRangeIndex1234(second.range[0])!
- .type;
- }
-}
-```
-
-
-

MODIFY
crates/rome_js_formatter/tests/specs/ts/assignment/type_assertion_assignment.ts.snap
crates/rome_js_formatter/tests/specs/ts/assignment/type_assertion_assignment.ts.snap
@@ -30,8 +30,8 @@ let x;
(<boolean>x) = true;
-(x.very.long.chain.of.static.members.that.goes.on.for.ever.I.mean.it
- .for.ever as string) = veryLongExpression();
+(x.very.long.chain.of.static.members.that.goes.on.for.ever.I.mean.it.for
+ .ever as string) = veryLongExpression();
for (<boolean>x of []) {
}

feat(rome_js_formatter): Member assignment formatting (#3061)