From d78e802190e4e5a18c446554c29849cdf82825f0 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 13 May 2022 16:29:02 +0200 Subject: [PATCH] fix(formatter): Stable member chain printing (#2582) This PR simplifies the member printing logic to make sure its output is stable. This results in a small regression ``` Before: **File Based Average Prettier Similarity**: 69.29% **Line Based Average Prettier Similarity**: 64.28% After: **File Based Average Prettier Similarity**: 69.13% **Line Based Average Prettier Similarity**: 64.06% ``` But unblocks my work on refactoring the printer behaviour (which seems to trigger this now a lot), and #2458 --- .../src/utils/member_chain/flatten_item.rs | 19 --- .../src/utils/member_chain/groups.rs | 126 +----------------- .../src/utils/member_chain/mod.rs | 14 +- .../member-chain/complex_arguments.js.snap | 2 - .../expression/member-chain/computed.js.snap | 1 - .../member-chain/inline-merge.js.snap | 13 +- .../prettier/js/arrays/holes-in-args.js.snap | 1 - .../prettier/js/async/inline-await.js.snap | 2 - .../js/comments/dangling_array.js.snap | 9 +- .../function_expression.js.snap | 39 +++--- .../prettier/js/method-chain/comment.js.snap | 78 +++++------ .../js/method-chain/first_long.js.snap | 25 ++-- .../js/method-chain/inline_merge.js.snap | 12 +- .../js/method-chain/issue-4125.js.snap | 34 ++--- .../js/method-chain/multiple-members.js.snap | 1 - .../prettier/js/method-chain/pr-7889.js.snap | 26 ++-- .../js/optional-chaining/comments.js.snap | 10 +- .../prettier/js/performance/nested.js.snap | 74 +++------- .../js/test-declarations/jest-each.js.snap | 44 +++--- .../typescript/as/assignment2.ts.snap | 28 ++-- .../custom/typeParameters/variables.ts.snap | 29 ++-- .../typescript/method-chain/comment.ts.snap | 23 ++-- 22 files changed, 193 insertions(+), 417 deletions(-) diff --git a/crates/rome_js_formatter/src/utils/member_chain/flatten_item.rs b/crates/rome_js_formatter/src/utils/member_chain/flatten_item.rs index 896aab8a289..fb8efa8ef13 100644 --- a/crates/rome_js_formatter/src/utils/member_chain/flatten_item.rs +++ b/crates/rome_js_formatter/src/utils/member_chain/flatten_item.rs @@ -6,7 +6,6 @@ use rome_js_syntax::{ }; use rome_rowan::{AstNode, SyntaxResult}; use std::fmt::Debug; -use std::slice; #[derive(Clone)] /// Data structure that holds the node with its formatted version @@ -35,15 +34,6 @@ impl FlattenItem { } } - pub(crate) fn as_format_elements(&self) -> &[FormatElement] { - match self { - FlattenItem::StaticMember(_, elements) => elements, - FlattenItem::CallExpression(_, elements) => elements, - FlattenItem::ComputedExpression(_, elements) => elements, - FlattenItem::Node(_, element) => slice::from_ref(element), - } - } - pub(crate) fn as_syntax(&self) -> &JsSyntaxNode { match self { FlattenItem::StaticMember(node, _) => node.syntax(), @@ -53,15 +43,6 @@ impl FlattenItem { } } - pub(crate) fn has_leading_comments(&self) -> bool { - match self { - FlattenItem::StaticMember(node, _) => node.syntax().has_leading_comments(), - FlattenItem::CallExpression(node, _) => node.syntax().has_leading_comments(), - FlattenItem::ComputedExpression(node, _) => node.syntax().has_leading_comments(), - FlattenItem::Node(node, _) => node.has_leading_comments(), - } - } - pub(crate) fn has_trailing_comments(&self) -> bool { match self { FlattenItem::StaticMember(node, _) => node.syntax().has_trailing_comments(), diff --git a/crates/rome_js_formatter/src/utils/member_chain/groups.rs b/crates/rome_js_formatter/src/utils/member_chain/groups.rs index a0a5e2686ad..56ddae3e817 100644 --- a/crates/rome_js_formatter/src/utils/member_chain/groups.rs +++ b/crates/rome_js_formatter/src/utils/member_chain/groups.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use crate::utils::member_chain::flatten_item::FlattenItem; use crate::utils::member_chain::simple_argument::SimpleArgument; -use rome_js_syntax::{JsAnyCallArgument, JsAnyExpression, JsCallExpression}; +use rome_js_syntax::JsCallExpression; use rome_rowan::{AstSeparatedList, SyntaxResult}; use std::mem; @@ -78,48 +78,19 @@ impl<'f> Groups<'f> { } /// It tells if the groups should be break on multiple lines - pub fn groups_should_break( - &self, - calls_count: usize, - head_group: &HeadGroup, - ) -> SyntaxResult { + pub fn groups_should_break(&self, calls_count: usize) -> SyntaxResult { // Do not allow the group to break if it only contains a single call expression if calls_count <= 1 { return Ok(false); } - let node_has_comments = self.has_comments() || head_group.has_comments(); // we want to check the simplicity of the call expressions only if we have at least // two of them // Check prettier: https://github.com/prettier/prettier/blob/main/src/language-js/print/member-chain.js#L389 - let call_expressions_are_not_simple = if calls_count > 2 { - self.call_expressions_are_not_simple()? - } else { - false - }; - let last_group_will_break_and_other_calls_have_function_arguments = - self.last_group_will_break_and_other_calls_have_function_arguments()?; - - // This emulates a simplified version of the similar logic found in the - // printer to force groups to break if they contain any "hard line - // break" (these not only include hard_line_break elements but also - // empty_line or tokens containing the "\n" character): The idea is - // that since any of these will force the group to break when it gets - // printed, the formatter needs to emit a group element for the call - // chain in the first place or it will not be printed correctly - let has_line_breaks = self - .groups - .iter() - .flat_map(|group| group.iter()) - .flat_map(|item| item.as_format_elements()) - .any(|element| element.will_break()); - - let should_break = has_line_breaks - || node_has_comments - || call_expressions_are_not_simple - || last_group_will_break_and_other_calls_have_function_arguments; + let call_expressions_are_not_simple = + calls_count > 2 && self.call_expressions_are_not_simple()?; - Ok(should_break) + Ok(call_expressions_are_not_simple) } fn into_formatted_groups(self) -> Vec { @@ -139,46 +110,9 @@ impl<'f> Groups<'f> { /// and the other one that goes on multiple lines. /// /// It's up to the printer to decide which one to use. - pub fn into_format_elements(self) -> (FormatElement, FormatElement) { + pub fn into_format_elements(self) -> FormatElement { let formatted_groups = self.into_formatted_groups(); - ( - concat_elements(formatted_groups.clone()), - join_elements(soft_line_break(), formatted_groups), - ) - } - - /// Checks if the groups contain comments. - pub fn has_comments(&self) -> bool { - let has_leading_comments = if self.groups.len() > 1 { - // SAFETY: access guarded by the previous check - self.groups - .iter() - .flat_map(|item| item.iter()) - .skip(1) - .any(|item| item.has_leading_comments()) - } else { - false - }; - let has_trailing_comments = self - .groups - .iter() - .flat_map(|item| item.iter()) - .any(|item| item.has_trailing_comments()); - - // This check might not be needed... trying to understand why Prettier has it - let cutoff_has_leading_comments = if self.groups.len() >= self.cutoff as usize { - self.groups - .get(self.cutoff as usize) - .map_or(false, |group| { - group - .first() - .map_or(false, |group| group.has_leading_comments()) - }) - } else { - false - }; - - has_leading_comments || has_trailing_comments || cutoff_has_leading_comments + concat_elements(formatted_groups) } /// Filters the stack of [FlattenItem] and return only the ones that @@ -210,48 +144,6 @@ impl<'f> Groups<'f> { })) } - /// Checks if the last group will break - by emulating the behaviour of the printer, - /// or if there's a call expression that contain a function/arrow function as argument - pub fn last_group_will_break_and_other_calls_have_function_arguments( - &self, - ) -> SyntaxResult { - let last_group = self.groups.iter().flat_map(|group| group.iter()).last(); - - if let Some(last_group) = last_group { - let element = last_group.as_format_elements().last(); - let group_will_break = element.map_or(false, |element| element.will_break()); - - let is_call_expression = last_group.is_loose_call_expression(); - - Ok(group_will_break - && is_call_expression - && self.call_expressions_have_function_or_arrow_func_as_argument()?) - } else { - Ok(false) - } - } - - /// Checks if any of the call expressions contains arguments that are functions or arrow - /// functions. - pub fn call_expressions_have_function_or_arrow_func_as_argument(&self) -> SyntaxResult { - for call_expression in self.get_call_expressions() { - let arguments = call_expression.arguments()?; - for argument in arguments.args() { - if matches!( - argument?, - JsAnyCallArgument::JsAnyExpression(JsAnyExpression::JsFunctionExpression(_)) - | JsAnyCallArgument::JsAnyExpression( - JsAnyExpression::JsArrowFunctionExpression(_) - ) - ) { - return Ok(true); - } - } - } - - Ok(false) - } - /// This is an heuristic needed to check when the first element of the group /// Should be part of the "head" or the "tail". fn should_not_wrap(&self, first_group: &HeadGroup) -> SyntaxResult { @@ -332,8 +224,4 @@ impl HeadGroup { pub fn expand_group(&mut self, group: Vec) { self.items.extend(group) } - - fn has_comments(&self) -> bool { - self.items.iter().any(|item| item.has_trailing_comments()) - } } diff --git a/crates/rome_js_formatter/src/utils/member_chain/mod.rs b/crates/rome_js_formatter/src/utils/member_chain/mod.rs index efa2cab3845..84f10bd49b3 100644 --- a/crates/rome_js_formatter/src/utils/member_chain/mod.rs +++ b/crates/rome_js_formatter/src/utils/member_chain/mod.rs @@ -289,7 +289,8 @@ fn format_groups( head_group: HeadGroup, groups: Groups, ) -> FormatResult { - if groups.groups_should_break(calls_count, &head_group)? { + // TODO use Alternatives once available + if groups.groups_should_break(calls_count)? { Ok(format_elements![ head_group.into_format_element(), group_elements(indent(format_elements![ @@ -298,13 +299,10 @@ fn format_groups( ]),) ]) } else { - let head_formatted = head_group.into_format_element(); - let (one_line, _) = groups.into_format_elements(); - - // TODO: this is not the definitive solution, as there are few restrictions due to how the printer works: - // - groups that contains other groups with hard lines break all the groups - // - conditionally print one single line is subject to how the printer works (by default, multiline) - Ok(format_elements![head_formatted, one_line]) + Ok(format_elements![ + head_group.into_format_element(), + groups.into_format_elements() + ]) } } diff --git a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/complex_arguments.js.snap b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/complex_arguments.js.snap index 30362b72a9e..9e5610ee66e 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/complex_arguments.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/complex_arguments.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs -assertion_line: 242 expression: complex_arguments.js - --- # Input client.execute( diff --git a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap index 2fd938c1979..b1648a2e2bc 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/computed.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs -assertion_line: 242 expression: computed.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap index 81a71e12494..24de06a8681 100644 --- a/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap +++ b/crates/rome_js_formatter/tests/specs/js/module/expression/member-chain/inline-merge.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/spec_test.rs -assertion_line: 242 expression: inline-merge.js - --- # Input _.flatMap(this.visibilityHandlers, fn => fn()) @@ -30,10 +28,9 @@ _.flatMap(this.visibilityHandlers, (fn) => fn()) .concat(this.record.resolved_legacy_visrules) .filter(Boolean); -Object.keys(availableLocales({ test: true })) - .forEach( - (locale) => { - // ... - }, - ); +Object.keys(availableLocales({ test: true })).forEach( + (locale) => { + // ... + }, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/holes-in-args.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/holes-in-args.js.snap index e5fb4d0297f..5fda75dab0f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/arrays/holes-in-args.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/arrays/holes-in-args.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: holes-in-args.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/async/inline-await.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/async/inline-await.js.snap index fd6b29217af..561707fef16 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/async/inline-await.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/async/inline-await.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 125 expression: inline-await.js - --- # Input ```js diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap index 1657309d6a3..1c1b80126f0 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/comments/dangling_array.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 125 expression: dangling_array.js - --- # Input ```js @@ -16,10 +14,9 @@ expect(() => {}).toTriggerReadyStateChanges([ # Output ```js -expect(() => {}) - .toTriggerReadyStateChanges([ - // Nothing. - ]); +expect(() => {}).toTriggerReadyStateChanges([ + // Nothing. +]); [1 /* first comment */ , 2 /* second comment */ , 3]; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap index e9259c68d8c..6ad920c652f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/function-first-param/function_expression.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: function_expression.js --- # Input @@ -35,29 +34,25 @@ db.collection('indexOptionDefault').createIndex({ a: 1 }, { # Output ```js //https://github.com/prettier/prettier/issues/3002 -beep - .boop() - .baz( - "foo", - { some: { thing: { nested: true } } }, - { another: { thing: true } }, - () => {}, - ); +beep.boop().baz( + "foo", + { some: { thing: { nested: true } } }, + { another: { thing: true } }, + () => {}, +); //https://github.com/prettier/prettier/issues/2984 -db - .collection("indexOptionDefault") - .createIndex( - { a: 1 }, - { indexOptionDefaults: true, w: 2, wtimeout: 1000 }, - function (err) { - test.equal(null, err); - test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern); - - client.close(); - done(); - }, - ); +db.collection("indexOptionDefault").createIndex( + { a: 1 }, + { indexOptionDefaults: true, w: 2, wtimeout: 1000 }, + function (err) { + test.equal(null, err); + test.deepEqual({ w: 2, wtimeout: 1000 }, commandResult.writeConcern); + + client.close(); + done(); + }, +); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap index 62234c37495..5b85bcccc2e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/comment.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: comment.js --- # Input @@ -65,75 +64,66 @@ angular.module('AngularAppModule') ```js function f() { return observableFromSubscribeFunction() - // Debounce manually rather than using editor.onDidStopChanging so that the debounce time is - // configurable. - .debounceTime(debounceInterval); + // Debounce manually rather than using editor.onDidStopChanging so that the debounce time is + // configurable. + .debounceTime(debounceInterval); } _.a(a) - /* very very very very very very very long such that it is longer than 80 columns */ - .a(); +/* very very very very very very very long such that it is longer than 80 columns */ +.a(); -_.a(a) - /* very very very very very very very long such that it is longer than 80 columns */ - .a(); +_.a(a).a(); /* very very very very very very very long such that it is longer than 80 columns */ -_.a(a) - /* very very very very very very very long such that it is longer than 80 columns */ - .a(); +_.a(a).a(); /* very very very very very very very long such that it is longer than 80 columns */ Something // $FlowFixMe(>=0.41.0) .getInstance(this.props.dao).getters(); // Warm-up first -measure() - .then(() => { - SomethingLong(); - }); +measure().then(() => { + SomethingLong(); +}); -measure() +measure().then(() => { // Warm-up first - .then(() => { - SomethingLong(); - }); + SomethingLong(); +}); -const configModel = this.baseConfigurationService - .getCache() - .consolidated // global/default values (do NOT modify) - .merge(this.cachedWorkspaceConfig); +const configModel = this.baseConfigurationService.getCache().consolidated.merge( + // global/default values (do NOT modify) + this.cachedWorkspaceConfig, +); -this.doWriteConfiguration(target, value, options) +this.doWriteConfiguration(target, value, options).then( // queue up writes to prevent race conditions - .then( - () => null, - (error) => { - return options.donotNotifyError ? TPromise.wrapError(error) : this.onError( - error, - target, - value, - ); - }, - ); + () => null, + (error) => { + return options.donotNotifyError ? TPromise.wrapError(error) : this.onError( + error, + target, + value, + ); + }, +); ret = __DEV__ ? // $FlowFixMe: this type differs according to the env vm.runInContext(source, ctx) : a; -angular - .module("AngularAppModule") - // Hello, I am comment. - .constant("API_URL", "http://localhost:8080/api"); +angular.module("AngularAppModule") +// Hello, I am comment. +.constant("API_URL", "http://localhost:8080/api"); ``` # Lines exceeding max width of 80 characters ``` - 3: // Debounce manually rather than using editor.onDidStopChanging so that the debounce time is - 9: /* very very very very very very very long such that it is longer than 80 columns */ - 13: /* very very very very very very very long such that it is longer than 80 columns */ - 17: /* very very very very very very very long such that it is longer than 80 columns */ - 46: return options.donotNotifyError ? TPromise.wrapError(error) : this.onError( + 3: // Debounce manually rather than using editor.onDidStopChanging so that the debounce time is + 9: /* very very very very very very very long such that it is longer than 80 columns */ + 12: _.a(a).a(); /* very very very very very very very long such that it is longer than 80 columns */ + 14: _.a(a).a(); /* very very very very very very very long such that it is longer than 80 columns */ ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap index 5625bf415cf..c09055525d5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/first_long.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: first_long.js --- # Input @@ -45,19 +44,17 @@ function f() { # Output ```js export default function theFunction(action$, store) { - return action$ - .ofType(THE_ACTION) - .switchMap( - (action) => - Observable.webSocket({ - url: THE_URL, - more: stuff(), - evenMore: stuff({ value1: true, value2: false, value3: false }), - }) - .filter((data) => theFilter(data)) - .map(({ theType, ...data }) => theMap(theType, data)) - .retryWhen((errors) => errors), - ); + return action$.ofType(THE_ACTION).switchMap( + (action) => + Observable.webSocket({ + url: THE_URL, + more: stuff(), + evenMore: stuff({ value1: true, value2: false, value3: false }), + }) + .filter((data) => theFilter(data)) + .map(({ theType, ...data }) => theMap(theType, data)) + .retryWhen((errors) => errors), + ); } function f() { diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap index 23ad1228f2f..86668e688c5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/inline_merge.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: inline_merge.js --- # Input @@ -28,12 +27,11 @@ var jqxhr = $.ajax("example.php") # Output ```js -Object.keys(availableLocales({ test: true })) - .forEach( - (locale) => { - // ... - }, - ); +Object.keys(availableLocales({ test: true })).forEach( + (locale) => { + // ... + }, +); this.layoutPartsToHide = this.utils.hashset( diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap index 918380246ec..afc24bb79fc 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/issue-4125.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: issue-4125.js --- # Input @@ -180,11 +179,7 @@ somePromise // you can still force multi-line chaining with a comment: const sha256_2 = (data) => - crypto - // breakme - .createHash("sha256") - .update(data) - .digest("hex"); + crypto.createHash("sha256").update(data).digest("hex"); // breakme // examples from https://github.com/prettier/prettier/pull/4765 @@ -247,10 +242,7 @@ const date = moment.utc(userInput).hour(0).minute(0).second(0); fetchUser(id).then(fetchAccountForUser).catch(handleFetchError); -fetchUser(id) - // - .then(fetchAccountForUser) - .catch(handleFetchError); +fetchUser(id).then(fetchAccountForUser).catch(handleFetchError); // // examples from https://github.com/prettier/prettier/issues/3107 @@ -260,18 +252,16 @@ function HelloWorld() { authorizationToken: data.token, }).initVerify("foo_container"); - fejax - .ajax({ url: "/verification/", dataType: "json" }) - .then( - (data) => { - this.setState({ isLoading: false }); - this.initWidget(data); - }, - (data) => { - this.logImpression("foo_fetch_error", data); - Flash.error(I18n.t("offline_identity.foo_issue")); - }, - ); + fejax.ajax({ url: "/verification/", dataType: "json" }).then( + (data) => { + this.setState({ isLoading: false }); + this.initWidget(data); + }, + (data) => { + this.logImpression("foo_fetch_error", data); + Flash.error(I18n.t("offline_identity.foo_issue")); + }, + ); } action$ diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap index 034bcbb8dd4..ce6de777774 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/multiple-members.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: multiple-members.js --- # Input diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/pr-7889.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/pr-7889.js.snap index a900f541656..e92ca33466d 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/pr-7889.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/pr-7889.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 149 expression: pr-7889.js - --- # Input ```js @@ -22,25 +20,21 @@ const Profile2 = view.with({ name }).as((props) => ( # Output ```js -const Profile = view - .with({ name: (state) => state.name }) - .as( - (props) => ( -
+const Profile = view.with({ name: (state) => state.name }).as( + (props) => ( +

Hello, {props.name}

- ), - ); + ), +); -const Profile2 = view - .with({ name }) - .as( - (props) => ( -
+const Profile2 = view.with({ name }).as( + (props) => ( +

Hello, {props.name}

- ), - ); + ), +); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/comments.js.snap index 4edf457e54f..b537e2bc223 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/comments.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/optional-chaining/comments.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 125 expression: comments.js - --- # Input ```js @@ -58,11 +56,9 @@ foo.bar.baz # Output ```js function foo() { - return a - .b() - .c() - // Comment - ?.d(); + return a.b().c() + // Comment + ?.d(); } fooBar diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap index 2ad3c13d4ea..4d3d3cd62ea 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/performance/nested.js.snap @@ -1,8 +1,6 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 125 expression: nested.js - --- # Input ```js @@ -40,63 +38,35 @@ someObject.someFunction().then(function() { # Output ```js -someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - return someObject - .someFunction() - .then(function () { - anotherFunction(); - }); - }); - }); - }); - }); - }); - }); +someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + return someObject.someFunction().then(function () { + anotherFunction(); }); + }); }); + }); }); + }); }); + }); }); + }); }); + }); }); +}); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap index 1ad1c5b6f4d..23cd5435328 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/jest-each.js.snap @@ -1,6 +1,5 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs -assertion_line: 175 expression: jest-each.js --- # Input @@ -131,29 +130,26 @@ ${11111111111} | ${a() ${1} | ${2} | ${3} ${2} | ${1} | ${3}`; -describe - .each([1, 2, 3])( - "test", - (a) => { - expect(a).toBe(a); - }, - ); - -test.only - .each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( - ".add(%i, %i)", - (a, b, expected) => { - expect(a + b).toBe(expected); - }, - ); - -test - .each([{ a: "1", b: 1 }, { a: "2", b: 2 }, { a: "3", b: 3 }])( - "test", - ({ a, b }) => { - expect(Number(a)).toBe(b); - }, - ); +describe.each([1, 2, 3])( + "test", + (a) => { + expect(a).toBe(a); + }, +); + +test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( + ".add(%i, %i)", + (a, b, expected) => { + expect(a + b).toBe(expected); + }, +); + +test.each([{ a: "1", b: 1 }, { a: "2", b: 2 }, { a: "3", b: 3 }])( + "test", + ({ a, b }) => { + expect(Number(a)).toBe(b); + }, +); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap index 5a15dd448c5..919b719fbcc 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/as/assignment2.ts.snap @@ -42,19 +42,17 @@ const defaultMaskGetter = $parse(attrs[directiveName]) as (scope: ng.IScope) => (this.configuration as any) = (this.editor as any) = (this.editorBody as any) = undefined; -angular - .module("foo") - .directive( - "formIsolator", - () => { - return { - name: "form", - controller: class FormIsolatorController { - $addControl = angular.noop; - } as ng.IControllerConstructor, - }; - }, - ); +angular.module("foo").directive( + "formIsolator", + () => { + return { + name: "form", + controller: class FormIsolatorController { + $addControl = angular.noop; + } as ng.IControllerConstructor, + }; + }, +); (this.selectorElem as any) = this.multiselectWidget = this.initialValues = undefined; @@ -77,7 +75,7 @@ const originalPrototype = originalConstructor.prototype as # Lines exceeding max width of 80 characters ``` 1: const defaultMaskGetter = $parse(attrs[directiveName]) as (scope: ng.IScope) => Mask; - 24: (attrs.rendererAttrs && this.utils.safeParseJsonString(attrs.rendererAttrs)) || Object.create( - 29: const annotate = (angular.injector as any).$$annotate as (fn: Function) => string[]; + 22: (attrs.rendererAttrs && this.utils.safeParseJsonString(attrs.rendererAttrs)) || Object.create( + 27: const annotate = (angular.injector as any).$$annotate as (fn: Function) => string[]; ``` 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 17c0ce277ee..c59a36fb514 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 @@ -44,15 +44,13 @@ const baaaaaaaaaaaaaaar: SomeThing< } > = looooooooooooooooooooooooooooooongNameFunc(); const baaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); -const isAnySuccessfulAttempt$: Observable = this._quizService - .isAnySuccessfulAttempt$() - .pipe( - tap( - (isAnySuccessfulAttempt: boolean) => { - this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; - }, - ), - ); +const isAnySuccessfulAttempt$: Observable = this._quizService.isAnySuccessfulAttempt$().pipe( + tap( + (isAnySuccessfulAttempt: boolean) => { + this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; + }, + ), +); const isAnySuccessfulAttempt2$: Observable = this._someMethodWithLongName(); const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); @@ -67,11 +65,12 @@ const fooooooooooooooo: SomeThing = looooooooooooooooooooooooo 9: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); 10: const baaaaaaaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); 16: const baaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); - 26: const isAnySuccessfulAttempt2$: Observable = this._someMethodWithLongName(); - 27: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); - 28: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); - 29: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); - 30: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); - 31: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); + 17: const isAnySuccessfulAttempt$: Observable = this._quizService.isAnySuccessfulAttempt$().pipe( + 24: const isAnySuccessfulAttempt2$: Observable = this._someMethodWithLongName(); + 25: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); + 26: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); + 27: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); + 28: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); + 29: const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap index f33a3f8c0ba..c8f5a0ecd6b 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/method-chain/comment.ts.snap @@ -18,22 +18,21 @@ this.firebase.object(`/shops/${shopLocation.shop}`) # Output ```js -this.firebase - .object(`/shops/${shopLocation.shop}`) - // keep distance info - .first( - (shop: ShopQueryResult, index: number, source: Observable): any => { - // add distance to result - const s = shop; - s.distance = shopLocation.distance; - return s; - }, - ); +this.firebase.object(`/shops/${shopLocation.shop}`) +// keep distance info +.first( + (shop: ShopQueryResult, index: number, source: Observable): any => { + // add distance to result + const s = shop; + s.distance = shopLocation.distance; + return s; + }, +); ``` # Lines exceeding max width of 80 characters ``` - 5: (shop: ShopQueryResult, index: number, source: Observable): any => { + 4: (shop: ShopQueryResult, index: number, source: Observable): any => { ```