fix(rome_js_formatter): assignment layout
MODIFY
crates/rome_js_formatter/src/lib.rs
crates/rome_js_formatter/src/lib.rs
@@ -861,17 +861,12 @@ function() {
// use this test check if your snippet prints as you wish, without using a snapshot
fn quick_test() {
let src = r#"
-const b4 = (
- <div>
- Text <a data-very-long-prop-breakline-rome-playground data-other>
- some link
- </a>{" "}
- | some other text,{" "}
- </div>
-);
+const gitBaseExtension = extensions.getExtension<GitBaseExtension>(
+ "vscode.git-base",
+ )!.exports;
"#;
- let syntax = SourceType::jsx();
+ let syntax = SourceType::tsx();
let tree = parse(src, FileId::zero(), syntax);
let options = JsFormatOptions::new(syntax);

MODIFY
crates/rome_js_formatter/src/utils/assignment_like.rs
crates/rome_js_formatter/src/utils/assignment_like.rs
@@ -441,19 +441,15 @@ impl JsAnyAssignmentLike {
let name = name?;
- let is_short = if f.context().comments().is_suppressed(name.syntax()) {
+ if f.context().comments().is_suppressed(name.syntax()) {
write!(f, [format_suppressed_node(name.syntax())])?;
- false
} else {
- let width = write_member_name(&name.into(), f)?;
- let text_width_for_break =
- (u8::from(f.options().tab_width()) + MIN_OVERLAP_FOR_BREAK) as usize;
- width < text_width_for_break && property_annotation.is_none()
+ write_member_name(&name.into(), f)?;
};
write!(f, [property_annotation.format()])?;
- Ok(is_short)
+ Ok(false)
}
JsAnyAssignmentLike::TsPropertySignatureClassMember(
property_signature_class_member,
@@ -1032,6 +1028,7 @@ fn is_poorly_breakable_member_or_call_chain(
while let Some(node) = expression.take() {
expression = match node {
+ JsAnyExpression::TsNonNullAssertionExpression(assertion) => assertion.expression().ok(),
JsAnyExpression::JsCallExpression(call_expression) => {
is_chain = true;
let callee = call_expression.callee()?;

DELETE
crates/rome_js_formatter/tests/specs/prettier/typescript/non-null/member-chain.ts.snap
----
-source: crates/rome_js_formatter/tests/prettier_tests.rs
----
-
-# Input
-
-```js
-const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!;
-
-const { somePropThatHasAReallyLongName2, anotherPropThatHasALongName2 } = this.props.imReallySureAboutThis!.anotherObject;
-
-this.foo.get("bar")!.doThings().more();
-
-foo!.bar().baz().what();
-```
-
-
-# Prettier differences
-
-```diff
---- Prettier
-+++ Rome
-@@ -1,8 +1,8 @@
- const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } =
- this.props.imReallySureAboutThis!;
-
--const { somePropThatHasAReallyLongName2, anotherPropThatHasALongName2 } =
-- this.props.imReallySureAboutThis!.anotherObject;
-+const { somePropThatHasAReallyLongName2, anotherPropThatHasALongName2 } = this
-+ .props.imReallySureAboutThis!.anotherObject;
-
- this.foo.get("bar")!.doThings().more();
-
-```
-
-# Output
-
-```js
-const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } =
- this.props.imReallySureAboutThis!;
-
-const { somePropThatHasAReallyLongName2, anotherPropThatHasALongName2 } = this
- .props.imReallySureAboutThis!.anotherObject;
-
-this.foo.get("bar")!.doThings().more();
-
-foo!.bar().baz().what();
-```
-
-
-

MODIFY
crates/rome_js_formatter/tests/specs/ts/assignment/assignment.ts
crates/rome_js_formatter/tests/specs/ts/assignment/assignment.ts
@@ -7,3 +7,7 @@ loooooooooooooooooooooooooong2 = void void "looooooooooooooooooooooooooooooooooo
loooooooooooooooooooooooooong7 =
// rome-ignore format: test
! "looooooooooooooooooooooooooooooooooooooooooog"!;
+
+const gitBaseExtension = extensions.getExtension<GitBaseExtension>(
+ "vscode.git-base",
+)!.exports;

MODIFY
crates/rome_js_formatter/tests/specs/ts/assignment/assignment.ts.snap
crates/rome_js_formatter/tests/specs/ts/assignment/assignment.ts.snap
@@ -13,6 +13,10 @@ loooooooooooooooooooooooooong7 =
// rome-ignore format: test
! "looooooooooooooooooooooooooooooooooooooooooog"!;
+const gitBaseExtension = extensions.getExtension<GitBaseExtension>(
+ "vscode.git-base",
+)!.exports;
+
=============================
# Outputs
## Output 1
@@ -34,3 +38,6 @@ loooooooooooooooooooooooooong7 =
// rome-ignore format: test
! "looooooooooooooooooooooooooooooooooooooooooog"!;
+const gitBaseExtension =
+ extensions.getExtension<GitBaseExtension>("vscode.git-base")!.exports;
+

ADD
crates/rome_js_formatter/tests/specs/ts/class/assigment_layout.ts
+class SourceRemoveUnused extends SourceAction {
+ static readonly kind = vscode.CodeActionKind.Source.append(
+ "removeUnused",
+ ).append("ts");
+
+ public static readonly id = "javascript-walkthrough.commands.nodeInstallationFound";
+}

ADD
crates/rome_js_formatter/tests/specs/ts/class/assigment_layout.ts.snap
+---
+source: crates/rome_js_formatter/tests/spec_test.rs
+expression: assigment_layout.ts
+---
+# Input
+class SourceRemoveUnused extends SourceAction {
+ static readonly kind = vscode.CodeActionKind.Source.append(
+ "removeUnused",
+ ).append("ts");
+
+ public static readonly id = "javascript-walkthrough.commands.nodeInstallationFound";
+}
+
+=============================
+# Outputs
+## Output 1
+-----
+Indent style: Tab
+Line width: 80
+Quote style: Double Quotes
+Quote properties: As needed
+-----
+class SourceRemoveUnused extends SourceAction {
+ static readonly kind =
+ vscode.CodeActionKind.Source.append("removeUnused").append("ts");
+
+ public static readonly id =
+ "javascript-walkthrough.commands.nodeInstallationFound";
+}
+

fix(rome_js_formatter): assignment layout #3386 (#3431)