From 9a767d6a716647ea7c8ae89533640fd74259ef9b Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Tue, 20 Sep 2022 11:18:24 +0200 Subject: [PATCH] test(rome_js_formatter): Add prettier's JSX tests (#3255) --- .../rome_js_formatter/tests/prettier_tests.rs | 2 +- ...k-line-between-specifiers.js.prettier-snap | 2 - .../blank-line-between-specifiers.js.snap | 80 - .../specs/prettier/js/if/trailing_comment.js | 7 - .../prettier/js/if/trailing_comment.js.snap | 27 +- .../js/import-assertions/re-export.js | 2 +- .../re-export.js.prettier-snap | 2 +- .../specs/prettier/js/method-chain/13018.js | 8 + .../js/method-chain/13018.js.prettier-snap | 20 + .../prettier/js/method-chain/13018.js.snap | 69 + .../specs/prettier/js/range/function-body.js | 3 + .../js/range/function-body.js.prettier-snap | 3 + .../prettier/js/range/function-body.js.snap | 37 + .../tests/specs/prettier/js/record/spread.js | 1 - .../specs/prettier/js/record/spread.js.snap | 3 +- .../prettier/js/strings/multiline-literal.js | 9 + .../multiline-literal.js.prettier-snap | 10 + .../js/strings/multiline-literal.js.snap | 55 + .../test_declarations.js.prettier-snap | 80 +- .../test_declarations.js.snap | 92 +- .../prettier/jsx/attr-element/attr-element.js | 2 + .../attr-element.js.prettier-snap | 12 + .../relational-operators.js | 19 + .../relational-operators.js.prettier-snap | 19 + .../tests/specs/prettier/jsx/do/do.js | 5 + .../specs/prettier/jsx/do/do.js.prettier-snap | 5 + .../tests/specs/prettier/jsx/do/do.js.snap | 61 + .../tests/specs/prettier/jsx/escape/escape.js | 1 + .../jsx/escape/escape.js.prettier-snap | 1 + .../tests/specs/prettier/jsx/escape/nbsp.js | 13 + .../prettier/jsx/escape/nbsp.js.prettier-snap | 9 + .../tests/specs/prettier/jsx/fbt/test.js | 115 ++ .../prettier/jsx/fbt/test.js.prettier-snap | 104 ++ .../tests/specs/prettier/jsx/fbt/test.js.snap | 281 ++++ .../specs/prettier/jsx/fragment/fragment.js | 72 + .../jsx/fragment/fragment.js.prettier-snap | 72 + .../prettier/jsx/fragment/fragment.js.snap | 202 +++ .../specs/prettier/jsx/ignore/jsx_ignore.js | 56 + .../jsx/ignore/jsx_ignore.js.prettier-snap | 55 + .../prettier/jsx/ignore/jsx_ignore.js.snap | 193 +++ .../prettier/jsx/multiline-assign/test.js | 19 + .../multiline-assign/test.js.prettier-snap | 31 + .../jsx/namespace/jsx_namespaced_name.js | 3 + .../jsx_namespaced_name.js.prettier-snap | 3 + .../tests/specs/prettier/jsx/newlines/test.js | 94 ++ .../jsx/newlines/test.js.prettier-snap | 57 + .../specs/prettier/jsx/newlines/test.js.snap | 193 +++ .../specs/prettier/jsx/newlines/windows.js | 3 + .../jsx/newlines/windows.js.prettier-snap | 1 + .../jsx/significant-space/comments.js | 7 + .../comments.js.prettier-snap | 7 + .../prettier/jsx/significant-space/test.js | 74 + .../significant-space/test.js.prettier-snap | 117 ++ .../jsx/significant-space/test.js.snap | 290 ++++ .../single-attribute-per-line.js | 27 + ...single-attribute-per-line.js.prettier-snap | 38 + .../specs/prettier/jsx/split-attrs/test.js | 49 + .../jsx/split-attrs/test.js.prettier-snap | 170 ++ .../prettier/jsx/split-attrs/test.js.snap | 261 ++++ .../specs/prettier/jsx/spread/attribute.js | 25 + .../jsx/spread/attribute.js.prettier-snap | 36 + .../prettier/jsx/spread/attribute.js.snap | 115 ++ .../tests/specs/prettier/jsx/spread/child.js | 23 + .../jsx/spread/child.js.prettier-snap | 32 + .../specs/prettier/jsx/spread/child.js.snap | 116 ++ .../prettier/jsx/stateless-arrow-fn/test.js | 73 + .../stateless-arrow-fn/test.js.prettier-snap | 170 ++ .../jsx/stateless-arrow-fn/test.js.snap | 300 ++++ .../jsx/template/styled-components.js | 18 + .../styled-components.js.prettier-snap | 19 + .../jsx/template/styled-components.js.snap | 75 + .../specs/prettier/jsx/text-wrap/test.js | 458 ++++++ .../jsx/text-wrap/test.js.prettier-snap | 570 +++++++ .../specs/prettier/jsx/text-wrap/test.js.snap | 1390 +++++++++++++++++ .../tests/specs/prettier/prepare_tests.js | 8 + .../conditional-types/issue-13275.ts | 1 + .../issue-13275.ts.prettier-snap | 1 + .../enum/computed-members.ts.prettier-snap | 6 +- .../typescript/enum/computed-members.ts.snap | 8 +- .../jsdoc_only_types.ts.prettier-snap | 4 +- .../error-recovery/jsdoc_only_types.ts.snap | 6 +- .../prettier/typescript/interface2/break.ts | 4 +- .../typescript/interface2/break.ts.snap | 61 +- .../prettier/typescript/literal/multiline.ts | 6 + .../literal/multiline.ts.prettier-snap | 7 + .../typescript/literal/multiline.ts.snap | 47 + .../typescript/typeof-this/decorators.ts | 6 + .../typeof-this/decorators.ts.prettier-snap | 6 + .../typescript/typeof-this/decorators.ts.snap | 46 + .../typescript/typeof-this/typeof-this.ts | 3 + .../typeof-this/typeof-this.ts.prettier-snap | 3 + 91 files changed, 6710 insertions(+), 186 deletions(-) delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.prettier-snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.snap create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts create mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts.prettier-snap diff --git a/crates/rome_js_formatter/tests/prettier_tests.rs b/crates/rome_js_formatter/tests/prettier_tests.rs index e3fbc3c72aa..503668524ee 100644 --- a/crates/rome_js_formatter/tests/prettier_tests.rs +++ b/crates/rome_js_formatter/tests/prettier_tests.rs @@ -31,7 +31,7 @@ struct TestInfo { mod check_reformat; -tests_macros::gen_tests! {"tests/specs/prettier/{js,typescript}/**/*.{js,ts,jsx,tsx}", crate::test_snapshot, "script"} +tests_macros::gen_tests! {"tests/specs/prettier/{js,typescript,jsx}/**/*.{js,ts,jsx,tsx}", crate::test_snapshot, "script"} const PRETTIER_IGNORE: &str = "prettier-ignore"; const ROME_IGNORE: &str = "rome-ignore format: prettier ignore"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.prettier-snap index 82cd20637b6..8856b3df341 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.prettier-snap @@ -1,7 +1,6 @@ export { // a foo1, - // b bar1, baz1, @@ -14,7 +13,6 @@ const baz2 = 1; export { // a foo2, - // b bar2, baz2, diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.snap deleted file mode 100644 index 51e23774716..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/export/blank-line-between-specifiers.js.snap +++ /dev/null @@ -1,80 +0,0 @@ ---- -source: crates/rome_js_formatter/tests/prettier_tests.rs ---- - -# Input - -```js -export { - // a - foo1, - - // b - bar1, - baz1, -} from "mod"; - -const foo2 = 1; -const bar2 = 1; -const baz2 = 1; - -export { - // a - foo2, - - // b - bar2, - baz2, -}; -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,7 +1,6 @@ - export { - // a - foo1, -- - // b - bar1, - baz1, -@@ -14,7 +13,6 @@ - export { - // a - foo2, -- - // b - bar2, - baz2, -``` - -# Output - -```js -export { - // a - foo1, - // b - bar1, - baz1, -} from "mod"; - -const foo2 = 1; -const bar2 = 1; -const baz2 = 1; - -export { - // a - foo2, - // b - bar2, - baz2, -}; -``` - - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js b/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js index 9b745ed0727..575cf4d57d2 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js @@ -10,10 +10,3 @@ if ( ) { a; } - -if ( - // comment - 1 -) { - b; -} diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js.snap index 964019986f2..1ff518ef544 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/if/trailing_comment.js.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: js/if/trailing_comment.js --- # Input @@ -17,13 +19,6 @@ if ( ) { a; } - -if ( - // comment - 1 -) { - b; -} ``` @@ -42,17 +37,6 @@ if ( } if (code === 92) { /* '\' */ -@@ -16,3 +15,10 @@ - ) { - a; - } -+ -+if ( -+ // comment -+ 1 -+) { -+ b; -+} ``` # Output @@ -75,13 +59,6 @@ if ( ) { a; } - -if ( - // comment - 1 -) { - b; -} ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js b/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js index dd9640ec20a..f7f9640a868 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js @@ -1,3 +1,3 @@ -export { foo2 } from "foo.json" assert { type: "json" }; +export { default as foo2 } from "foo.json" assert { type: "json" }; export * from "foo.json" assert { type: "json" }; export * as foo3 from "foo.json" assert { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js.prettier-snap index dd9640ec20a..f7f9640a868 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/import-assertions/re-export.js.prettier-snap @@ -1,3 +1,3 @@ -export { foo2 } from "foo.json" assert { type: "json" }; +export { default as foo2 } from "foo.json" assert { type: "json" }; export * from "foo.json" assert { type: "json" }; export * as foo3 from "foo.json" assert { type: "json" }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js new file mode 100644 index 00000000000..a0a4dc5ebf2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js @@ -0,0 +1,8 @@ +foo(_a).bar().leet(); +foo(-a).bar().leet(); +foo(+a).bar().leet(); +foo(~a).bar().leet(); +foo(++a).bar().leet(); +foo(--a).bar().leet(); +foo(a++).bar().leet(); +foo(a--).bar().leet(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.prettier-snap new file mode 100644 index 00000000000..7c19e0fb00b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.prettier-snap @@ -0,0 +1,20 @@ +foo(_a).bar().leet(); +foo(-a).bar().leet(); +foo(+a) + .bar() + .leet(); +foo(~a) + .bar() + .leet(); +foo(++a) + .bar() + .leet(); +foo(--a) + .bar() + .leet(); +foo(a++) + .bar() + .leet(); +foo(a--) + .bar() + .leet(); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.snap new file mode 100644 index 00000000000..d3a5c2b1867 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/method-chain/13018.js.snap @@ -0,0 +1,69 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: js/method-chain/13018.js +--- + +# Input + +```js +foo(_a).bar().leet(); +foo(-a).bar().leet(); +foo(+a).bar().leet(); +foo(~a).bar().leet(); +foo(++a).bar().leet(); +foo(--a).bar().leet(); +foo(a++).bar().leet(); +foo(a--).bar().leet(); +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,20 +1,8 @@ + foo(_a).bar().leet(); + foo(-a).bar().leet(); +-foo(+a) +- .bar() +- .leet(); +-foo(~a) +- .bar() +- .leet(); +-foo(++a) +- .bar() +- .leet(); +-foo(--a) +- .bar() +- .leet(); +-foo(a++) +- .bar() +- .leet(); +-foo(a--) +- .bar() +- .leet(); ++foo(+a).bar().leet(); ++foo(~a).bar().leet(); ++foo(++a).bar().leet(); ++foo(--a).bar().leet(); ++foo(a++).bar().leet(); ++foo(a--).bar().leet(); +``` + +# Output + +```js +foo(_a).bar().leet(); +foo(-a).bar().leet(); +foo(+a).bar().leet(); +foo(~a).bar().leet(); +foo(++a).bar().leet(); +foo(--a).bar().leet(); +foo(a++).bar().leet(); +foo(a--).bar().leet(); +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js b/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js new file mode 100644 index 00000000000..1705cd72985 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js @@ -0,0 +1,3 @@ +let fn =a((x ) => { +<<>> quux (); //<<>> +}); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.prettier-snap new file mode 100644 index 00000000000..b9dc6f74df6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.prettier-snap @@ -0,0 +1,3 @@ +let fn = a((x) => { + quux(); // +}); diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.snap new file mode 100644 index 00000000000..daadadf8510 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/range/function-body.js.snap @@ -0,0 +1,37 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: js/range/function-body.js +--- + +# Input + +```js +let fn =a((x ) => { + quux (); // +}); +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,3 +1,3 @@ +-let fn = a((x) => { ++let fn =a((x ) => { + quux(); // + }); +``` + +# Output + +```js +let fn =a((x ) => { + quux(); // +}); +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js b/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js index 765d4270d55..31bfe0c7667 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js +++ b/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js @@ -4,4 +4,3 @@ const taskLater = #{ ...taskNow, status: "DONE" } // A reminder: The ordering of keys in record literals does not affect equality (and is not retained) assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 }) - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js.snap index c5086def062..b45e5e818ec 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/record/spread.js.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: js/record/spread.js --- # Input @@ -11,7 +13,6 @@ const taskLater = #{ ...taskNow, status: "DONE" } // A reminder: The ordering of keys in record literals does not affect equality (and is not retained) assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 }) - ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js b/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js new file mode 100644 index 00000000000..fcecf64f399 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js @@ -0,0 +1,9 @@ +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.prettier-snap new file mode 100644 index 00000000000..5ccb636b7e7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.prettier-snap @@ -0,0 +1,10 @@ +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = "Multiline string\ + Multiline string\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.snap new file mode 100644 index 00000000000..caed317319a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/js/strings/multiline-literal.js.snap @@ -0,0 +1,55 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: js/strings/multiline-literal.js +--- + +# Input + +```js +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,6 +1,7 @@ + // https://github.com/prettier/prettier/pull/13274 + +-const loremIpsumFooBazBar1 = "Multiline string\ ++const loremIpsumFooBazBar1 = ++ "Multiline string\ + Multiline string\ + "; + +``` + +# Output + +```js +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = + "Multiline string\ + Multiline string\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.prettier-snap index 3bddc7bb29d..c07928430cd 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.prettier-snap @@ -85,43 +85,75 @@ skip(`does something really long and complicated so I have to write a very long skip("does something really long and complicated so I have to write a very long name for the test", () => {}); -test.step("does something really long and complicated so I have to write a very long name for the test", () => {}); +test.step( + "does something really long and complicated so I have to write a very long name for the test", + () => {}, +); -test.step(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +test.step( + `does something really long and complicated so I have to write a very long name for the test`, + () => {}, +); -test.describe("does something really long and complicated so I have to write a very long name for the test", () => {}); +test.describe( + "does something really long and complicated so I have to write a very long name for the test", + () => {}, +); -test.describe(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +test.describe( + `does something really long and complicated so I have to write a very long name for the test`, + () => {}, +); -test.describe - .only("does something really long and complicated so I have to write a very long name for the test", () => {}); +test.describe.only( + "does something really long and complicated so I have to write a very long name for the test", + () => {}, +); -test.describe - .only(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +test.describe.only( + `does something really long and complicated so I have to write a very long name for the test`, + () => {}, +); -test.describe - .parallel("does something really long and complicated so I have to write a very long name for the test", () => {}); +test.describe.parallel( + "does something really long and complicated so I have to write a very long name for the test", + () => {}, +); -test.describe - .parallel(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +test.describe.parallel( + `does something really long and complicated so I have to write a very long name for the test`, + () => {}, +); -test.describe.parallel - .only("does something really long and complicated so I have to write a very long name for the testThis is a very", () => {}); +test.describe.parallel.only( + "does something really long and complicated so I have to write a very long name for the testThis is a very", + () => {}, +); -test.describe.parallel - .only(`does something really long and complicated so I have to write a very long name for the testThis is a very`, () => {}); +test.describe.parallel.only( + `does something really long and complicated so I have to write a very long name for the testThis is a very`, + () => {}, +); -test.describe - .serial("does something really long and complicated so I have to write a very long name for the test", () => {}); +test.describe.serial( + "does something really long and complicated so I have to write a very long name for the test", + () => {}, +); -test.describe - .serial(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +test.describe.serial( + `does something really long and complicated so I have to write a very long name for the test`, + () => {}, +); -test.describe.serial - .only("does something really long and complicated so I have to write a very long name for the test", () => {}); +test.describe.serial.only( + "does something really long and complicated so I have to write a very long name for the test", + () => {}, +); -test.describe.serial - .only(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +test.describe.serial.only( + `does something really long and complicated so I have to write a very long name for the test`, + () => {}, +); // Should break diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap index 2b6182c096b..a3b6c802729 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/test-declarations/test_declarations.js.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: js/test-declarations/test_declarations.js --- # Input @@ -175,53 +177,97 @@ it( ```diff --- Prettier +++ Rome -@@ -93,35 +93,25 @@ +@@ -85,75 +85,33 @@ - test.describe(`does something really long and complicated so I have to write a very long name for the test`, () => {}); + skip("does something really long and complicated so I have to write a very long name for the test", () => {}); --test.describe -- .only("does something really long and complicated so I have to write a very long name for the test", () => {}); +-test.step( +- "does something really long and complicated so I have to write a very long name for the test", +- () => {}, +-); ++test.step("does something really long and complicated so I have to write a very long name for the test", () => {}); + +-test.step( +- `does something really long and complicated so I have to write a very long name for the test`, +- () => {}, +-); ++test.step(`does something really long and complicated so I have to write a very long name for the test`, () => {}); + +-test.describe( +- "does something really long and complicated so I have to write a very long name for the test", +- () => {}, +-); ++test.describe("does something really long and complicated so I have to write a very long name for the test", () => {}); + +-test.describe( +- `does something really long and complicated so I have to write a very long name for the test`, +- () => {}, +-); ++test.describe(`does something really long and complicated so I have to write a very long name for the test`, () => {}); + +-test.describe.only( +- "does something really long and complicated so I have to write a very long name for the test", +- () => {}, +-); +test.describe.only("does something really long and complicated so I have to write a very long name for the test", () => {}); --test.describe -- .only(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +-test.describe.only( +- `does something really long and complicated so I have to write a very long name for the test`, +- () => {}, +-); +test.describe.only(`does something really long and complicated so I have to write a very long name for the test`, () => {}); --test.describe -- .parallel("does something really long and complicated so I have to write a very long name for the test", () => {}); +-test.describe.parallel( +- "does something really long and complicated so I have to write a very long name for the test", +- () => {}, +-); +test.describe.parallel("does something really long and complicated so I have to write a very long name for the test", () => {}); --test.describe -- .parallel(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +-test.describe.parallel( +- `does something really long and complicated so I have to write a very long name for the test`, +- () => {}, +-); +test.describe.parallel(`does something really long and complicated so I have to write a very long name for the test`, () => {}); --test.describe.parallel -- .only("does something really long and complicated so I have to write a very long name for the testThis is a very", () => {}); +-test.describe.parallel.only( +- "does something really long and complicated so I have to write a very long name for the testThis is a very", +- () => {}, +-); +test.describe.parallel.only("does something really long and complicated so I have to write a very long name for the testThis is a very", () => {}); --test.describe.parallel -- .only(`does something really long and complicated so I have to write a very long name for the testThis is a very`, () => {}); +-test.describe.parallel.only( +- `does something really long and complicated so I have to write a very long name for the testThis is a very`, +- () => {}, +-); +test.describe.parallel.only(`does something really long and complicated so I have to write a very long name for the testThis is a very`, () => {}); --test.describe -- .serial("does something really long and complicated so I have to write a very long name for the test", () => {}); +-test.describe.serial( +- "does something really long and complicated so I have to write a very long name for the test", +- () => {}, +-); +test.describe.serial("does something really long and complicated so I have to write a very long name for the test", () => {}); --test.describe -- .serial(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +-test.describe.serial( +- `does something really long and complicated so I have to write a very long name for the test`, +- () => {}, +-); +test.describe.serial(`does something really long and complicated so I have to write a very long name for the test`, () => {}); --test.describe.serial -- .only("does something really long and complicated so I have to write a very long name for the test", () => {}); +-test.describe.serial.only( +- "does something really long and complicated so I have to write a very long name for the test", +- () => {}, +-); +test.describe.serial.only("does something really long and complicated so I have to write a very long name for the test", () => {}); --test.describe.serial -- .only(`does something really long and complicated so I have to write a very long name for the test`, () => {}); +-test.describe.serial.only( +- `does something really long and complicated so I have to write a very long name for the test`, +- () => {}, +-); +test.describe.serial.only(`does something really long and complicated so I have to write a very long name for the test`, () => {}); // Should break -@@ -152,10 +142,7 @@ +@@ -184,10 +142,7 @@ () => {}, ); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js new file mode 100644 index 00000000000..f31bd2306ce --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js @@ -0,0 +1,2 @@ + />; + />; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js.prettier-snap new file mode 100644 index 00000000000..fc79981e98a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/attr-element/attr-element.js.prettier-snap @@ -0,0 +1,12 @@ + + + +/>; + + + + + +/>; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js new file mode 100644 index 00000000000..41d6bcc8b72 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js @@ -0,0 +1,19 @@ +(
) < 5; +
> 5; +(
) < 5; +
> 5; + +
<= 5; +
>= 5; +
<= 5; +
>= 5; + +(
) <
; +
>
; +(
) <
; +
>
; + +
<=
; +
>=
; +
<=
; +
>=
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js.prettier-snap new file mode 100644 index 00000000000..41d6bcc8b72 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/binary-expressions/relational-operators.js.prettier-snap @@ -0,0 +1,19 @@ +(
) < 5; +
> 5; +(
) < 5; +
> 5; + +
<= 5; +
>= 5; +
<= 5; +
>= 5; + +(
) <
; +
>
; +(
) <
; +
>
; + +
<=
; +
>=
; +
<=
; +
>=
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js new file mode 100644 index 00000000000..7890763ee5b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js @@ -0,0 +1,5 @@ +
+ {do { + 1 + }} +
diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.prettier-snap new file mode 100644 index 00000000000..e3b5f2b7896 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.prettier-snap @@ -0,0 +1,5 @@ +
+ {do { + 1; + }} +
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.snap new file mode 100644 index 00000000000..b08a2e5f23a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/do/do.js.snap @@ -0,0 +1,61 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/do/do.js +--- + +# Input + +```js +
+ {do { + 1 + }} +
+``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,5 @@ +
+ {do { +- 1; ++ 1 + }} +-
; ++
+``` + +# Output + +```js +
+ {do { + 1 + }} +
+``` + + +# Errors +``` +error[SyntaxError]: expected `}` but instead found `do` + ┌─ do.js:2:4 + │ +2 │ {do { + │ ^^ unexpected + +error: Unexpected token. Did you mean `{'}'}` or `}`? + ┌─ do.js:4:4 + │ +4 │ }} + │ ^ + + +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js new file mode 100644 index 00000000000..db12ce51b7a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js @@ -0,0 +1 @@ +
<
diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js.prettier-snap new file mode 100644 index 00000000000..167cd46e48d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/escape.js.prettier-snap @@ -0,0 +1 @@ +
<
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js new file mode 100644 index 00000000000..87d434f5f84 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js @@ -0,0 +1,13 @@ +many_nbsp =
   
+single_nbsp =
 
+nbsp_with_newline = +
+   +
+ +many_raw_nbsp =
   
+many_raw_spaces =
+ + +amp = foo & bar +raw_amp = foo & bar diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js.prettier-snap new file mode 100644 index 00000000000..af7aed664c7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/escape/nbsp.js.prettier-snap @@ -0,0 +1,9 @@ +many_nbsp =
   
; +single_nbsp =
 
; +nbsp_with_newline =
 
; + +many_raw_nbsp =
   
; +many_raw_spaces =
; + +amp = foo & bar; +raw_amp = foo & bar; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js new file mode 100644 index 00000000000..1cc594b1957 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js @@ -0,0 +1,115 @@ +x = + + + First + , + + Second + + + +x = + + + First + + , + + Second + + + +x = + + First,Second + + +x = + + + First + , + Second + + + +x = + + Prefix comes before + + + suffix + + + + +x = + + Prefix comes before + + + suffix + + + + + suffix + + + + +x = + + Count Chocula knows the the number + + is awesome + + +x = ( + + {hour}:{minute}:{second} + +); + +x = ( + + {hour} + : + {minute} + : + {second} + +); + +x = ( + + {hour}: + {minute}: + {second} + +); + +first = ( + + Text
+ More text
+ And more
+
+); + +second = ( + + Text
More text
And more
+
+); + +third = ( + + Text +
+ More text +
+ And more +
+
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.prettier-snap new file mode 100644 index 00000000000..cf87039fe74 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.prettier-snap @@ -0,0 +1,104 @@ +x = ( + + First, + Second + +); + +x = ( + + First + , + Second + +); + +x = ( + + First,Second + +); + +x = ( + + First,Second + +); + +x = ( + + Prefix comes before + + suffix + + +); + +x = ( + + Prefix comes before + + suffix + + + suffix + + +); + +x = ( + + Count Chocula knows the the number + + is awesome + +); + +x = ( + + {hour}:{minute}:{second} + +); + +x = ( + + {hour} + : + {minute} + : + {second} + +); + +x = ( + + {hour}: + {minute}: + {second} + +); + +first = ( + + Text
+ More text
+ And more
+
+); + +second = ( + + Text
More text
And more
+
+); + +third = ( + + Text +
+ More text +
+ And more +
+
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.snap new file mode 100644 index 00000000000..ca247636882 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/fbt/test.js.snap @@ -0,0 +1,281 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/fbt/test.js +--- + +# Input + +```js +x = + + + First + , + + Second + + + +x = + + + First + + , + + Second + + + +x = + + First,Second + + +x = + + + First + , + Second + + + +x = + + Prefix comes before + + + suffix + + + + +x = + + Prefix comes before + + + suffix + + + + + suffix + + + + +x = + + Count Chocula knows the the number + + is awesome + + +x = ( + + {hour}:{minute}:{second} + +); + +x = ( + + {hour} + : + {minute} + : + {second} + +); + +x = ( + + {hour}: + {minute}: + {second} + +); + +first = ( + + Text
+ More text
+ And more
+
+); + +second = ( + + Text
More text
And more
+
+); + +third = ( + + Text +
+ More text +
+ And more +
+
+); +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -80,15 +80,23 @@ + + first = ( + +- Text
+- More text
+- And more
++ Text ++
++ More text ++
++ And more ++
+
+ ); + + second = ( + +- Text
More text
And more
++ Text ++
++ More text ++
++ And more ++
+
+ ); + +``` + +# Output + +```js +x = ( + + First, + Second + +); + +x = ( + + First + , + Second + +); + +x = ( + + First,Second + +); + +x = ( + + First,Second + +); + +x = ( + + Prefix comes before + + suffix + + +); + +x = ( + + Prefix comes before + + suffix + + + suffix + + +); + +x = ( + + Count Chocula knows the the number + + is awesome + +); + +x = ( + + {hour}:{minute}:{second} + +); + +x = ( + + {hour} + : + {minute} + : + {second} + +); + +x = ( + + {hour}: + {minute}: + {second} + +); + +first = ( + + Text +
+ More text +
+ And more +
+
+); + +second = ( + + Text +
+ More text +
+ And more +
+
+); + +third = ( + + Text +
+ More text +
+ And more +
+
+); +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js new file mode 100644 index 00000000000..c8c4657fd90 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js @@ -0,0 +1,72 @@ +<>; + +<> + text +; + +<> + + +; + +<> + text +

heading

+ text +

heading

+ text +; + +
+ <> + <> + Hello + world + + <> + Goodbye + world + + +
; + +foo = ( + // comment + <> +); + + + + +; + +< // open fragment +> + + +; + +[<>, <>]; +const fun1 = () => <>; +x = <> +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <> +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.prettier-snap new file mode 100644 index 00000000000..6c2f55893d6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.prettier-snap @@ -0,0 +1,72 @@ +<>; + +<>text; + +<> + + +; + +<> + text +

heading

+ text +

heading

+ text +; + +
+ <> + <> + Hello + world + + <> + Goodbye + world + + +
; + +foo = ( + // comment + <> +); + + + + +; + +< + // open fragment +> + + +; + +[<>, <>]; +const fun1 = () => <>; +x = <>; +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <>, +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.snap new file mode 100644 index 00000000000..24a6be4d5ab --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/fragment/fragment.js.snap @@ -0,0 +1,202 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/fragment/fragment.js +--- + +# Input + +```js +<>; + +<> + text +; + +<> + + +; + +<> + text +

heading

+ text +

heading

+ text +; + +
+ <> + <> + Hello + world + + <> + Goodbye + world + + +
; + +foo = ( + // comment + <> +); + + + + +; + +< // open fragment +> + + +; + +[<>, <>]; +const fun1 = () => <>; +x = <> +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <> +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -28,24 +28,22 @@ + +
; + +-foo = ( +- // comment +- <> +-); ++foo = ++ ( ++ // comment ++ <> ++ ); + +- ++< /* open fragment */ > + + +-; ++; + +-< ++<> + // open fragment +-> + + +-; ++; // close fragment + + [<>, <>]; + const fun1 = () => <>; +``` + +# Output + +```js +<>; + +<>text; + +<> + + +; + +<> + text +

heading

+ text +

heading

+ text +; + +
+ <> + <> + Hello + world + + <> + Goodbye + world + + +
; + +foo = + ( + // comment + <> + ); + +< /* open fragment */ > + + +; + +<> + // open fragment + + +; // close fragment + +[<>, <>]; +const fun1 = () => <>; +x = <>; +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <>, +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js new file mode 100644 index 00000000000..f540cd8b2a8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js @@ -0,0 +1,56 @@ +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +f( + + {/*prettier-ignore*/} + + +); + +// this be formatted +
+ {/* prettier-ignore */} foo + +
; + +// this should remain as-is +
+{ + /* prettier-ignore */ + foo ( ) +} +
; + +// this should remain as-is +
+{ + /* prettier-ignore */ + x ? : +} +
; + +push( + // prettier-ignore + :) + , +); + +function f() { + // rome-ignore format: Instability issue + return ( + // prettier-ignore + /* $FlowFixMe(>=0.53.0) */ + + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.prettier-snap new file mode 100644 index 00000000000..d90e35e6e80 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.prettier-snap @@ -0,0 +1,55 @@ +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +f( + + {/*prettier-ignore*/} + + , +); + +// this be formatted +
+ {/* prettier-ignore */} foo + +
; + +// this should remain as-is +
+ { + /* prettier-ignore */ + foo ( ) + } +
; + +// this should remain as-is +
+ { + /* prettier-ignore */ + x ? : + } +
; + +push( + // prettier-ignore + :) + , +); + +function f() { + return ( + // prettier-ignore + /* $FlowFixMe(>=0.53.0) */ + + ); +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.snap new file mode 100644 index 00000000000..7d74b6711bf --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/ignore/jsx_ignore.js.snap @@ -0,0 +1,193 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/ignore/jsx_ignore.js +--- + +# Input + +```js +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +f( + + {/*prettier-ignore*/} + + +); + +// this be formatted +
+ {/* prettier-ignore */} foo + +
; + +// this should remain as-is +
+{ + /* prettier-ignore */ + foo ( ) +} +
; + +// this should remain as-is +
+{ + /* prettier-ignore */ + x ? : +} +
; + +push( + // prettier-ignore + :) + , +); + +function f() { + // rome-ignore format: Instability issue + return ( + // prettier-ignore + /* $FlowFixMe(>=0.53.0) */ + + ); +} +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,20 +1,22 @@ + // this should remain as-is +
+ {/* prettier-ignore */} +- ++ +
; + + // this should remain as-is +
+ {/* prettier-ignore */} +- ++ +
; + + // this should remain as-is + f( + + {/*prettier-ignore*/} +- ++ + , + ); + +@@ -28,16 +30,15 @@ +
+ { + /* prettier-ignore */ +- foo ( ) ++ foo ( ) + } +
; + + // this should remain as-is +
+ { +- /* prettier-ignore */ +- x ? : +- } ++ /* prettier-ignore */ ++ x ? : } +
; + + push( +@@ -47,6 +48,7 @@ + ); + + function f() { ++ // rome-ignore format: Instability issue + return ( + // prettier-ignore + /* $FlowFixMe(>=0.53.0) */ +``` + +# Output + +```js +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +
+ {/* prettier-ignore */} + +
; + +// this should remain as-is +f( + + {/*prettier-ignore*/} + + , +); + +// this be formatted +
+ {/* prettier-ignore */} foo + +
; + +// this should remain as-is +
+ { + /* prettier-ignore */ + foo ( ) + } +
; + +// this should remain as-is +
+ { + /* prettier-ignore */ + x ? : } +
; + +push( + // prettier-ignore + :) + , +); + +function f() { + // rome-ignore format: Instability issue + return ( + // prettier-ignore + /* $FlowFixMe(>=0.53.0) */ + + ); +} +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js new file mode 100644 index 00000000000..7c3649a6e7c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js @@ -0,0 +1,19 @@ +const comp1 = ( +
+ Keep the wrapping parens. +
+); + +const comp2 =
+ Create wrapping parens. +
; + +comp2A =
+ Create wrapping parens. +
; + +const comp3 =
Bump to next line without parens
; + +const comp4 =
Create wrapping parens and indent all the things.
; + +const comp5 =
Keep it on one line.
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js.prettier-snap new file mode 100644 index 00000000000..810b627f7c3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/multiline-assign/test.js.prettier-snap @@ -0,0 +1,31 @@ +const comp1 = ( +
+ Keep the wrapping parens. +
+); + +const comp2 = ( +
+ Create wrapping parens. +
+); + +comp2A = ( +
+ Create wrapping parens. +
+); + +const comp3 = ( +
+ Bump to next line without parens +
+); + +const comp4 = ( +
+ Create wrapping parens and indent all the things. +
+); + +const comp5 =
Keep it on one line.
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js new file mode 100644 index 00000000000..7f4591ee043 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js @@ -0,0 +1,3 @@ +; + +1; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js.prettier-snap new file mode 100644 index 00000000000..7f4591ee043 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/namespace/jsx_namespaced_name.js.prettier-snap @@ -0,0 +1,3 @@ +; + +1; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js new file mode 100644 index 00000000000..d5fedf9e3ab --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js @@ -0,0 +1,94 @@ +keep =

+ Welcome to the Universal React Starter-kyt. + This starter kyt should serve as the base for an advanced, + server-rendered React app. +

+ +newlines_text = +
+ hi + there + how + + are you + + + are you fine today? +
+ +newlines_text_spaced = +
+ + space above + + space below + +
+ +newlines_elems_spaced = +
+ + space above + + space below + +
+ +newlines_mixed = +
+ hi + there + + how + + are you + + + are you fine today? +
+ +newlines_elems = +
+
+ + +
+ + +
+ + + hi + + +
+ + + + + + + + +
+ +regression_extra_newline = ( +
+ + New Messages +
+); + + +regression_extra_newline_2 = ( +
+ ( + + ) +
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.prettier-snap new file mode 100644 index 00000000000..19d48412ee7 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.prettier-snap @@ -0,0 +1,57 @@ +keep = ( +

+ Welcome to the Universal React Starter-kyt. This starter + kyt should serve as the base for an advanced, server-rendered React app. +

+); + +newlines_text =
hi there how are you are you fine today?
; + +newlines_text_spaced =
space above space below
; + +newlines_elems_spaced = ( +
+ space above + + space below +
+); + +newlines_mixed = ( +
+ hi + there + how are you + are you fine today? +
+); + +newlines_elems = ( +
+
+
+
+ hi +
+ + +
+); + +regression_extra_newline = ( +
+ + New Messages +
+); + +regression_extra_newline_2 = ( +
+ ( + + ) +
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.snap new file mode 100644 index 00000000000..6561133b729 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/test.js.snap @@ -0,0 +1,193 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/newlines/test.js +--- + +# Input + +```js +keep =

+ Welcome to the Universal React Starter-kyt. + This starter kyt should serve as the base for an advanced, + server-rendered React app. +

+ +newlines_text = +
+ hi + there + how + + are you + + + are you fine today? +
+ +newlines_text_spaced = +
+ + space above + + space below + +
+ +newlines_elems_spaced = +
+ + space above + + space below + +
+ +newlines_mixed = +
+ hi + there + + how + + are you + + + are you fine today? +
+ +newlines_elems = +
+
+ + +
+ + +
+ + + hi + + +
+ + + + + + + + +
+ +regression_extra_newline = ( +
+ + New Messages +
+); + + +regression_extra_newline_2 = ( +
+ ( + + ) +
+); +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -33,7 +33,9 @@ +
+ hi +
++ + ++ + +
+ ); +``` + +# Output + +```js +keep = ( +

+ Welcome to the Universal React Starter-kyt. This starter + kyt should serve as the base for an advanced, server-rendered React app. +

+); + +newlines_text =
hi there how are you are you fine today?
; + +newlines_text_spaced =
space above space below
; + +newlines_elems_spaced = ( +
+ space above + + space below +
+); + +newlines_mixed = ( +
+ hi + there + how are you + are you fine today? +
+); + +newlines_elems = ( +
+
+
+
+ hi +
+ + + + +
+); + +regression_extra_newline = ( +
+ + New Messages +
+); + +regression_extra_newline_2 = ( +
+ ( + + ) +
+); +``` + + +# Lines exceeding max width of 80 characters +``` + 45: +``` + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js new file mode 100644 index 00000000000..d2b04f35a93 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js @@ -0,0 +1,3 @@ +
+Text +
diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js.prettier-snap new file mode 100644 index 00000000000..a51f7aafaa9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/newlines/windows.js.prettier-snap @@ -0,0 +1 @@ +
Text
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js new file mode 100644 index 00000000000..7a0895dcb44 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js @@ -0,0 +1,7 @@ +
+ { + // TODO: don't harcode this space! not all locales use whitespace + // in the same way + ' ' + } +
diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js.prettier-snap new file mode 100644 index 00000000000..3632e7d413f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/comments.js.prettier-snap @@ -0,0 +1,7 @@ +
+ { + // TODO: don't harcode this space! not all locales use whitespace + // in the same way + " " + } +
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js new file mode 100644 index 00000000000..6f25e76bfdb --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js @@ -0,0 +1,74 @@ +after = + + foo bar + + +before = + + bar foo + + +before_break1 = + + foo + + +before_break2 = + + foo + + +after_break = + + foo + + +within = + + foo bar + + +break_components = +
+ + +

foobar bar bar

yep

+
+

nope

+
+ +var x =
+ hello hi sdkflsdfjk +
; + +nest_plz = +
+
+
+
+
+ +regression_not_transformed_1 = + ; + +regression_not_transformed_2 = + ; + +similar_1 = + ; + +similar_2 = + ; + +similar_3 = + ; + +not_broken_end = +
+ long text long text long text long text long text long text long text long text url long text long text +
+ +not_broken_begin = +
+
long text long text long text long text long text long text long text long texturl long text long text +
diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.prettier-snap new file mode 100644 index 00000000000..15330365b76 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.prettier-snap @@ -0,0 +1,117 @@ +after = ( + + foo bar + +); + +before = ( + + bar foo + +); + +before_break1 = ( + + {" "} + foo + +); + +before_break2 = ( + + {" "} + foo + +); + +after_break = ( + + foo{" "} + + +); + +within = ( + + foo bar + +); + +break_components = ( +
+ + +

+ foobar bar bar +

+

+ + yep + +

+
+

nope

+
+); + +var x = ( +
+ hello hi sdkflsdfjk +
+); + +nest_plz = ( +
+
+
+
+
+); + +regression_not_transformed_1 = ( + + {" "} + + +); + +regression_not_transformed_2 = ( + + {" "} + +); + +similar_1 = ( + + {" "} + + +); + +similar_2 = ( + + {" "} + +); + +similar_3 = ( + + + +); + +not_broken_end = ( +
+ long text long text long text long text long text long text long text long + text url long text long text +
+); + +not_broken_begin = ( +
+
long text long text long text long text long text long text long text + long texturl long text long text +
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.snap new file mode 100644 index 00000000000..054555963c5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/significant-space/test.js.snap @@ -0,0 +1,290 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/significant-space/test.js +--- + +# Input + +```js +after = + + foo bar + + +before = + + bar foo + + +before_break1 = + + foo + + +before_break2 = + + foo + + +after_break = + + foo + + +within = + + foo bar + + +break_components = +
+ + +

foobar bar bar

yep

+
+

nope

+
+ +var x =
+ hello hi sdkflsdfjk +
; + +nest_plz = +
+
+
+
+
+ +regression_not_transformed_1 = + ; + +regression_not_transformed_2 = + ; + +similar_1 = + ; + +similar_2 = + ; + +similar_3 = + ; + +not_broken_end = +
+ long text long text long text long text long text long text long text long text url long text long text +
+ +not_broken_begin = +
+
long text long text long text long text long text long text long text long texturl long text long text +
+``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -12,7 +12,7 @@ + + before_break1 = ( + +- {" "} ++ + foo + + ); +@@ -21,15 +21,16 @@ + + {" "} ++ /> + foo + + ); + + after_break = ( + +- foo{" "} +- ++ foo + + ); + +@@ -79,7 +80,8 @@ + + regression_not_transformed_2 = ( + +- {" "} ++ ++ {" "} + + ); + +@@ -92,13 +94,15 @@ + + similar_2 = ( + +- {" "} ++ ++ {" "} + + ); + + similar_3 = ( + +- ++ ++ + + ); + +@@ -111,7 +115,8 @@ + + not_broken_begin = ( +
+-
long text long text long text long text long text long text long text +- long texturl long text long text ++
++ long text long text long text long text long text long text long text long ++ texturl long text long text +
+ ); +``` + +# Output + +```js +after = ( + + foo bar + +); + +before = ( + + bar foo + +); + +before_break1 = ( + + + foo + +); + +before_break2 = ( + + + foo + +); + +after_break = ( + + foo + +); + +within = ( + + foo bar + +); + +break_components = ( +
+ + +

+ foobar bar bar +

+

+ + yep + +

+
+

nope

+
+); + +var x = ( +
+ hello hi sdkflsdfjk +
+); + +nest_plz = ( +
+
+
+
+
+); + +regression_not_transformed_1 = ( + + {" "} + + +); + +regression_not_transformed_2 = ( + + + {" "} + +); + +similar_1 = ( + + {" "} + + +); + +similar_2 = ( + + + {" "} + +); + +similar_3 = ( + + + + +); + +not_broken_end = ( +
+ long text long text long text long text long text long text long text long + text url long text long text +
+); + +not_broken_begin = ( +
+
+ long text long text long text long text long text long text long text long + texturl long text long text +
+); +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js new file mode 100644 index 00000000000..299cb8332aa --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js @@ -0,0 +1,27 @@ +import React from "react"; + +const Component = () => ( +
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ + + + bar + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js.prettier-snap new file mode 100644 index 00000000000..c447f80ded5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/single-attribute-per-line/single-attribute-per-line.js.prettier-snap @@ -0,0 +1,38 @@ +import React from "react"; + +const Component = () => ( +
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+ + + + bar + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js new file mode 100644 index 00000000000..59f3a7a8ae1 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js @@ -0,0 +1,49 @@ +long_closed = + + +long_open = + + hello + + +long_open_long_children = + + + Hello world + +
hey hiya how are ya
+
+
+
+
+ d + + + +short_closed = + + +short_open = + + hello + + +make_self_closing = +
+ + + +
+ +leave_opening = + + +long_string = +
hello world
+ +long_string_with_extra_param = +
hello world
+ +// rome-ignore format: Instability issue +long_obj = +
hello world
diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.prettier-snap new file mode 100644 index 00000000000..1a4851d6ae5 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.prettier-snap @@ -0,0 +1,170 @@ +long_closed = ( + +); + +long_open = ( + + hello + +); + +long_open_long_children = ( + + + Hello world + +
+
+
+
+
+
hey hiya how are ya
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + d + + + + + +); + +short_closed = ; + +short_open = ( + + hello + +); + +make_self_closing = ( +
+ + +
+); + +leave_opening = ( + + {" "} + +); + +long_string = ( +
+ hello world +
+); + +long_string_with_extra_param = ( +
+ hello world +
+); + +long_obj = ( +
+ hello world +
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.snap new file mode 100644 index 00000000000..9042378ed7f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/split-attrs/test.js.snap @@ -0,0 +1,261 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/split-attrs/test.js +--- + +# Input + +```js +long_closed = + + +long_open = + + hello + + +long_open_long_children = + + + Hello world + +
hey hiya how are ya
+
+
+
+
+ d + + + +short_closed = + + +short_open = + + hello + + +make_self_closing = +
+ + + +
+ +leave_opening = + + +long_string = +
hello world
+ +long_string_with_extra_param = +
hello world
+ +// rome-ignore format: Instability issue +long_obj = +
hello world
+``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -155,16 +155,6 @@ +
+ ); + +-long_obj = ( +-
+- hello world +-
+-); ++// rome-ignore format: Instability issue ++long_obj = ++
hello world
+``` + +# Output + +```js +long_closed = ( + +); + +long_open = ( + + hello + +); + +long_open_long_children = ( + + + Hello world + +
+
+
+
+
+
hey hiya how are ya
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + d + + + + + +); + +short_closed = ; + +short_open = ( + + hello + +); + +make_self_closing = ( +
+ + +
+); + +leave_opening = ( + + {" "} + +); + +long_string = ( +
+ hello world +
+); + +long_string_with_extra_param = ( +
+ hello world +
+); + +// rome-ignore format: Instability issue +long_obj = +
hello world
+``` + + +# Lines exceeding max width of 80 characters +``` + 144:
+ 151: className="i use bootstrap and just put loooaads of classnames in here all the time" + 160:
hello world
+``` + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js new file mode 100644 index 00000000000..2f12f980007 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js @@ -0,0 +1,25 @@ +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.prettier-snap new file mode 100644 index 00000000000..a4fa06210ae --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.prettier-snap @@ -0,0 +1,36 @@ +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.snap new file mode 100644 index 00000000000..39071cb7e1f --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/attribute.js.snap @@ -0,0 +1,115 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/spread/attribute.js +--- + +# Input + +```js +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -9,28 +9,21 @@ +
; + +
; + +
; + +
; + +
; +``` + +# Output + +```js +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; + +
; +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js new file mode 100644 index 00000000000..94e59bf6d24 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js @@ -0,0 +1,23 @@ +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */...a}
; + +// rome-ignore format: Instability issue +
{...a //comment +}
; + +
{...a + //comment +}
; + +
{ + //comment + ...a +}
; + +// rome-ignore format: Instability issue +
{//comment + ...a // comment +}
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.prettier-snap new file mode 100644 index 00000000000..fc218066144 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.prettier-snap @@ -0,0 +1,32 @@ +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */ ...a}
; + +
+ { + ...a //comment + } +
; + +
+ { + ...a + //comment + } +
; + +
+ { + //comment + ...a + } +
; + +
+ { + //comment + ...a // comment + } +
; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.snap new file mode 100644 index 00000000000..5358e69534a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/spread/child.js.snap @@ -0,0 +1,116 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/spread/child.js +--- + +# Input + +```js +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */...a}
; + +// rome-ignore format: Instability issue +
{...a //comment +}
; + +
{...a + //comment +}
; + +
{ + //comment + ...a +}
; + +// rome-ignore format: Instability issue +
{//comment + ...a // comment +}
; +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -4,29 +4,23 @@ + +
{/* comment */ ...a}
; + +-
+- { +- ...a //comment +- } +-
; ++// rome-ignore format: Instability issue ++
{...a //comment ++}
; + +
+- { +- ...a +- //comment ++ {...a ++ //comment + } +
; + +
+ { +- //comment +- ...a +- } ++ //comment ++ ...a} +
; + +-
+- { +- //comment +- ...a // comment +- } +-
; ++// rome-ignore format: Instability issue ++
{//comment ++ ...a // comment ++}
; +``` + +# Output + +```js +
{...a}
; + +
{...a /* comment */}
; + +
{/* comment */ ...a}
; + +// rome-ignore format: Instability issue +
{...a //comment +}
; + +
+ {...a + //comment + } +
; + +
+ { + //comment + ...a} +
; + +// rome-ignore format: Instability issue +
{//comment + ...a // comment +}
; +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js new file mode 100644 index 00000000000..2099e5bc09a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js @@ -0,0 +1,73 @@ +const render1 = ({ styles }) => ( +
+ Keep the wrapping parens. Put each key on its own line. +
+); + +const render2 = ({ styles }) =>
+ Create wrapping parens. +
; + +const render3 = ({ styles }) =>
Create wrapping parens.
; + +const render4 = ({ styles }) =>
Create wrapping parens and indent all the things.
; + +const render5 = ({ styles }) =>
Keep it on one line.
; + +const render6 = ({ styles }) => ( +
+
ddd d dd d d dddd dddd hello
+
ddd d dd d d dddd dddd hello
+
+
ddd d dd d d dddd dddd hello
hello
+
+) + +const render7 = () => +
+ Dont break each elem onto its own line. +
+
+ +const render7A = () => ( +
+
+
+) + +const render7B = () => ( +
+ Dont break plz + Dont break plz + Dont break plz +
+) + +const render8 = (props) =>
{props.text}
+const render9 = (props) =>
{props.looooooooooooooooooooooooooooooong_text}
+const render10 = (props) =>
{props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents}
+ +const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd) + +React.render( + + , document.querySelector('#react-root') +) + + +const renderTernary = (props) => + + {props.showTheThing ? + Hello world + : "hello " + "howdy! "} + {props.showTheThing ? + Hello world + : + null + } + {props.showTheThing ? null : + Hello world + } + {props.showTheOtherThing ?
I am here
:
} + {props.showTheOtherThing ?
I am here!!
: null} + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.prettier-snap new file mode 100644 index 00000000000..7cbcef966ad --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.prettier-snap @@ -0,0 +1,170 @@ +const render1 = ({ styles }) => ( +
+ Keep the wrapping parens. Put each key on its own line. +
+); + +const render2 = ({ styles }) => ( +
+ Create wrapping parens. +
+); + +const render3 = ({ styles }) => ( +
+ Create wrapping parens. +
+); + +const render4 = ({ styles }) => ( +
+ Create wrapping parens and indent all the things. +
+); + +const render5 = ({ styles }) =>
Keep it on one line.
; + +const render6 = ({ styles }) => ( +
+
+ ddd d dd d d dddd dddd hello +
+
+ ddd d dd d d dddd dddd hello +
+
+
+ ddd d dd d d dddd dddd hello +
{" "} + hello +
+
+); + +const render7 = () => ( +
+ + Dont break each elem onto its own line. +
+
+); + +const render7A = () => ( +
+
+
+
+
+); + +const render7B = () => ( +
+ + {" "} + Dont break plz + + + + Dont break plz + + + Dont break plz + + +
+); + +const render8 = (props) =>
{props.text}
; +const render9 = (props) => ( +
{props.looooooooooooooooooooooooooooooong_text}
+); +const render10 = (props) => ( +
+ {props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents} +
+); + +const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => + this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams( + cccccccccccc, + dddddddddddddddddddddd, + ); + +React.render( + , + document.querySelector("#react-root"), +); + +const renderTernary = (props) => ( + + {props.showTheThing ? ( + + Hello world + + ) : ( + "hello " + "howdy! " + )} + {props.showTheThing ? ( + + Hello world + + ) : null} + {props.showTheThing ? null : ( + + Hello world + + )} + {props.showTheOtherThing ?
I am here
:
} + {props.showTheOtherThing ?
I am here!!
: null} + +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.snap new file mode 100644 index 00000000000..bd71e968e67 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/stateless-arrow-fn/test.js.snap @@ -0,0 +1,300 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/stateless-arrow-fn/test.js +--- + +# Input + +```js +const render1 = ({ styles }) => ( +
+ Keep the wrapping parens. Put each key on its own line. +
+); + +const render2 = ({ styles }) =>
+ Create wrapping parens. +
; + +const render3 = ({ styles }) =>
Create wrapping parens.
; + +const render4 = ({ styles }) =>
Create wrapping parens and indent all the things.
; + +const render5 = ({ styles }) =>
Keep it on one line.
; + +const render6 = ({ styles }) => ( +
+
ddd d dd d d dddd dddd hello
+
ddd d dd d d dddd dddd hello
+
+
ddd d dd d d dddd dddd hello
hello
+
+) + +const render7 = () => +
+ Dont break each elem onto its own line. +
+
+ +const render7A = () => ( +
+
+
+) + +const render7B = () => ( +
+ Dont break plz + Dont break plz + Dont break plz +
+) + +const render8 = (props) =>
{props.text}
+const render9 = (props) =>
{props.looooooooooooooooooooooooooooooong_text}
+const render10 = (props) =>
{props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents}
+ +const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd) + +React.render( + + , document.querySelector('#react-root') +) + + +const renderTernary = (props) => + + {props.showTheThing ? + Hello world + : "hello " + "howdy! "} + {props.showTheThing ? + Hello world + : + null + } + {props.showTheThing ? null : + Hello world + } + {props.showTheOtherThing ?
I am here
:
} + {props.showTheOtherThing ?
I am here!!
: null} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -55,7 +55,7 @@ + attr4 + > + ddd d dd d d dddd dddd hello +-
{" "} ++
+ hello +
+
+@@ -65,7 +65,8 @@ +
+ + Dont break each elem onto its own line. +-
++
++
+
+ ); + +@@ -81,7 +82,8 @@ +
+ + {" "} +- Dont break plz ++ ++ Dont break plz + + + +``` + +# Output + +```js +const render1 = ({ styles }) => ( +
+ Keep the wrapping parens. Put each key on its own line. +
+); + +const render2 = ({ styles }) => ( +
+ Create wrapping parens. +
+); + +const render3 = ({ styles }) => ( +
+ Create wrapping parens. +
+); + +const render4 = ({ styles }) => ( +
+ Create wrapping parens and indent all the things. +
+); + +const render5 = ({ styles }) =>
Keep it on one line.
; + +const render6 = ({ styles }) => ( +
+
+ ddd d dd d d dddd dddd hello +
+
+ ddd d dd d d dddd dddd hello +
+
+
+ ddd d dd d d dddd dddd hello +
+ hello +
+
+); + +const render7 = () => ( +
+ + Dont break each elem onto its own line. +
+
+
+); + +const render7A = () => ( +
+
+
+
+
+); + +const render7B = () => ( +
+ + {" "} + + Dont break plz + + + + Dont break plz + + + Dont break plz + + +
+); + +const render8 = (props) =>
{props.text}
; +const render9 = (props) => ( +
{props.looooooooooooooooooooooooooooooong_text}
+); +const render10 = (props) => ( +
+ {props.even_looooooooooooooooooooooooooooooooooooooooooonger_contents} +
+); + +const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => + this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams( + cccccccccccc, + dddddddddddddddddddddd, + ); + +React.render( + , + document.querySelector("#react-root"), +); + +const renderTernary = (props) => ( + + {props.showTheThing ? ( + + Hello world + + ) : ( + "hello " + "howdy! " + )} + {props.showTheThing ? ( + + Hello world + + ) : null} + {props.showTheThing ? null : ( + + Hello world + + )} + {props.showTheOtherThing ?
I am here
:
} + {props.showTheOtherThing ?
I am here!!
: null} + +); +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js new file mode 100644 index 00000000000..3377c40783a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js @@ -0,0 +1,18 @@ +; + +; + +; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.prettier-snap new file mode 100644 index 00000000000..d47d923e3c3 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.prettier-snap @@ -0,0 +1,19 @@ +; + +; + +; diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.snap new file mode 100644 index 00000000000..020bfb36ac6 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/template/styled-components.js.snap @@ -0,0 +1,75 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/template/styled-components.js +--- + +# Input + +```js +; + +; + +; +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -11,9 +11,8 @@ + `}; + + ; +``` + +# Output + +```js +; + +; + +; +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js b/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js new file mode 100644 index 00000000000..f8cb6255443 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js @@ -0,0 +1,458 @@ +// Wrapping text +x = +
+ Some text that would need to wrap on to a new line in order to display correctly and nicely +
+ +// Wrapping tags +x = +
+ f f f f f f +
+ +// Wrapping tags +x = +
+ ffffff +
+ +// Wrapping tags +x = + + +// Wrapping tags +x = +
+ f +
+ +x = +
+ before
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at mollis lorem.
after +
+ +x = +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}{stuff}{stuff}after{stuff}after +
+ +x = +
+ before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after {stuff} {stuff} {stuff} after {stuff} after +
+ +x = +
+ Please state your name and occupation for the board of school directors. +
+ +function DiffOverview(props) { + const { source, target, since } = props; + return ( +
+
+

+ This diff overview is computed against the current list of records in + this collection and the list it contained on {humanDate(since)}. +

+

+ Note: last_modified and schema record metadata + are omitted for easier review. +

+
+ +
+ ); +} + +x = Starting at minute {graphActivity.startTime}, running for {graphActivity.length} to minute {graphActivity.startTime + graphActivity.length} + +x = +
+ First second third +
Something
+
+ +x = +
+
+ First +
+ Second +
+ Third +
+
+ +x = +
+ First
+ Second +
Third +
+ +leading_whitespace = +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +trailing_whitespace = +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +no_leading_or_trailing_whitespace = +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +facebook_translation_leave_text_around_tag = +
+ + First + , + ( + Second + ) +
+ +x = +
+ + First second third fourth fifth sixth seventh + , + ( + Second + ) +
+ +this_really_should_split_across_lines = +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after +
+ +unstable_before = +
+ Your score: {`${mini.crosstable.users[sessionUserId]} - ${mini.crosstable.users[user.id]}`} +
+ +unstable_after_first_run = ( +
+ Your score:{" "} + {`${mini.crosstable.users[sessionUserId]} - ${mini + .crosstable.users[user.id]}`} +
+); + +solitary_whitespace = +
+ +jsx_whitespace_on_newline = +
+
+ First +
+ Second +
+ Third +
+
+ +jsx_around_multiline_element = +
Before
{"Enough text to make this element wrap on to multiple lines when formatting"}
After
+ +jsx_around_multiline_element_second_pass = ( +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
{" "} + After +
+); + +convert_space_expressions = +
{" "}
+ +x = +
+ + + + + + +
+ +const Abc = () => { + return ( +
+ Please state your + {" "} + name + {" "} + and + {" "} + occupation + {" "} + for the board of directors. +
+ ); +}; + +x =
Some stuff here
+ +headers_and_paragraphs = ( +
+

First

+

The first paragraph.

+ +

Second

+

The second paragraph.

+
+); + +no_text_one_tag_per_line = +
+ +
+ +with_text_fill_line = +
+ Text +
+ +line_after_br = +
+ Text
+ More text
+ And more
+
+ +line_after_br = +
+ Text
More text
And more
+
+ +line_after_br = +
+ Text +
+ More text +
+ And more +
+
+ +line_after_br_2 =
A
B
C
+ +br_followed_by_whitespace =

text
+ +dont_preserve_blank_lines_when_jsx_contains_text = +
+ +
Zeroth
+ +
First
+ + Second + +
+ +multiple_expressions = +
+ {header} + {body} + {footer} +
+ +single_expression_child_tags = +
+ You currently have {dashboardStr} and {userStr} +
+ +expression_does_not_break = +
texty text text text text text text text text text text text {this.props.type}
+ +// FIXME +br_triggers_expression_break = +

+ text text text text text text text text text text text {this.props.type}
+ +jsx_whitespace_after_tag = +
+ + {variable} + + {" "} + ({variable}) +
+ +x = +
+ ENDS IN
+ text text text text text text text text text text text +
{" "} + HRS +
+ +x = +
+

Message

+ Hello, I'm a simple message. +
+ +x = +
+ Hello, I'm a simple message. +

Message

+
+ +x = +
+
+
+
+
+ Line {startRange.row + 1}:{startRange.column + 1} - {endRange.row + 1}:{endRange.column + 1}{caller} +
+
+
+
+
+ +x = +
+ {" "}
text
+
+ +// NOTE: Multiple JSX whitespaces are collapsed into a single space. +x = +
+ {" "}{" "}{" "} +
+ +// Don't break a self-closing element without attributes +// ---------- +x = +

+ text text text text text text text text text text text text text text text
text text text text text text +

; + +x = +
+
+ First +
- +
+ Second +
+
+ +x = +
+
+ First +
+ - +
+ Second +
+
+ +x = +
+
First
-
Second
+
+ +x = +
+
+ First +
- +
+ Second +
+
+ +x = +
+
+ First +
+ - +
+ Second +
+
+ +x = +
+
First
-
Second
+
+ +x = +
+ {hour}:{minute}:{second} +
+ +x = +
+ {hour} + : + {minute} + : + {second} +
+ +x = +
+ {hour}: + {minute}: + {second} +
+ +x =
text here.
+ +x =
Sales tax estimated using a rate of {salesTax * 100}%.
+ +x =
+ {title}  +
+ +x =
bar
+ +x =
+ + {name}’s{' '} + + Hello world.
+ You {type}ed this shipment to +
+ +x = + {parameter.Description}: {errorMsg} + + +x = + +x = Copy "{name}" + +x = (avg. {value}/5) + +x =

+ Use the Button's +

; + +this_really_should_split_across_lines = +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after +
+ +let myDiv = ReactTestUtils.renderIntoDocument( +
+
, +
+
+); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.prettier-snap new file mode 100644 index 00000000000..8d55c7a9103 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.prettier-snap @@ -0,0 +1,570 @@ +// Wrapping text +x = ( +
+ Some text that would need to wrap on to a new line in order to display + correctly and nicely +
+); + +// Wrapping tags +x = ( +
+ f f f f{" "} + f f +
+); + +// Wrapping tags +x = ( +
+ f + f + f + f + f + f +
+); + +// Wrapping tags +x = ( +
+); + +// Wrapping tags +x = ( +
+ {" "} + f +
+); + +x = ( +
+ before +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at + mollis lorem. +
+ after +
+); + +x = ( +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + {stuff} + {stuff}after{stuff}after +
+); + +x = ( +
+ before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after{" "} + {stuff} {stuff} {stuff} after {stuff} after +
+); + +x = ( +
+ Please state your name and occupation for the board of{" "} + school directors. +
+); + +function DiffOverview(props) { + const { source, target, since } = props; + return ( +
+
+

+ This diff overview is computed against the current list of records in + this collection and the list it contained on {humanDate(since)} + . +

+

+ Note: last_modified and schema record + metadata are omitted for easier review. +

+
+ +
+ ); +} + +x = ( + + + Starting at minute {graphActivity.startTime}, running for{" "} + {graphActivity.length} to minute{" "} + {graphActivity.startTime + graphActivity.length} + + +); + +x = ( +
+ First second third +
+ Something +
+
+); + +x = ( +
+
First
+ Second +
Third
+
+); + +x = ( +
+ First
Second
Third +
+); + +leading_whitespace = ( +
+ {" "} + First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh + Twelfth Thirteenth Fourteenth +
+); + +trailing_whitespace = ( +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh + Twelfth Thirteenth Fourteenth{" "} +
+); + +no_leading_or_trailing_whitespace = ( +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh + Twelfth Thirteenth Fourteenth +
+); + +facebook_translation_leave_text_around_tag = ( +
+ First, (Second) +
+); + +x = ( +
+ First second third fourth fifth sixth seventh, ( + Second) +
+); + +this_really_should_split_across_lines = ( +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + after{stuff}after{stuff}after +
+); + +unstable_before = ( +
+ Your score:{" "} + {`${mini.crosstable.users[sessionUserId]} - ${ + mini.crosstable.users[user.id] + }`} +
+); + +unstable_after_first_run = ( +
+ Your score:{" "} + {`${mini.crosstable.users[sessionUserId]} - ${ + mini.crosstable.users[user.id] + }`} +
+); + +solitary_whitespace = ( +
+ {" "} +
+); + +jsx_whitespace_on_newline = ( +
+
First
Second
Third
+
+); + +jsx_around_multiline_element = ( +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
{" "} + After +
+); + +jsx_around_multiline_element_second_pass = ( +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
{" "} + After +
+); + +convert_space_expressions =
; + +x = ( +
+ + + + + + +
+); + +const Abc = () => { + return ( +
+ Please state your name and occupation for the board of + directors. +
+ ); +}; + +x =
Some stuff here
; + +headers_and_paragraphs = ( +
+

First

+

The first paragraph.

+ +

Second

+

The second paragraph.

+
+); + +no_text_one_tag_per_line = ( +
+ + +
+); + +with_text_fill_line = ( +
+ Text + +
+); + +line_after_br = ( +
+ Text +
+ More text +
+ And more +
+
+); + +line_after_br = ( +
+ Text +
+ More text +
+ And more +
+
+); + +line_after_br = ( +
+ Text +
+ More text +
+ And more +
+
+); + +line_after_br_2 = ( +
+ A
B
C +
+); + +br_followed_by_whitespace = ( +
+
text +
+); + +dont_preserve_blank_lines_when_jsx_contains_text = ( +
+
Zeroth
+
First
+ Second +
+); + +multiple_expressions = ( +
+ {header} + {body} + {footer} +
+); + +single_expression_child_tags = ( +
+ You currently have {dashboardStr} and{" "} + {userStr} +
+); + +expression_does_not_break = ( +
+ texty text text text text text text text text text text text{" "} + {this.props.type}{" "} +
+); + +// FIXME +br_triggers_expression_break = ( +
+
+ text text text text text text text text text text text { + this.props.type + }{" "} +
+); + +jsx_whitespace_after_tag = ( +
+ + {variable} + {" "} + ({variable}) +
+); + +x = ( +
+ ENDS IN
text text text text text text text text text text text
{" "} + HRS +
+); + +x = ( +
+

Message

+ Hello, I'm a simple message. +
+); + +x = ( +
+ Hello, I'm a simple message. +

Message

+
+); + +x = ( +
+
+
+
+
+ Line {startRange.row + 1}:{startRange.column + 1} -{" "} + {endRange.row + 1}:{endRange.column + 1} + {caller} +
+
+
+
+
+); + +x = ( +
+ {" "} +
text
+
+); + +// NOTE: Multiple JSX whitespaces are collapsed into a single space. +x =
; + +// Don't break a self-closing element without attributes +// ---------- +x = ( +

+ text text text text text text text text text text text text text text text +
+ text text text text text text +

+); + +x = ( +
+
First
-
Second
+
+); + +x = ( +
+
First
-
Second
+
+); + +x = ( +
+
First
-
Second
+
+); + +x = ( +
+
+ First +
+ - +
+ Second +
+
+); + +x = ( +
+
+ First +
+ - +
+ Second +
+
+); + +x = ( +
+
+ First +
+ - +
+ Second +
+
+); + +x = ( +
+ {hour}:{minute}:{second} +
+); + +x = ( +
+ {hour}:{minute}:{second} +
+); + +x = ( +
+ {hour}:{minute}:{second} +
+); + +x = ( +
+ text here.
+
+); + +x =
Sales tax estimated using a rate of {salesTax * 100}%.
; + +x =
{title} 
; + +x = ( +
+ + bar +
+); + +x = ( +
+ + {name}’s{" "} + + Hello world.
+ You {type}ed this shipment to +
+); + +x = ( + + {parameter.Description}: {errorMsg} + +); + +x = ( + +); + +x = Copy "{name}"; + +x = (avg. {value}/5); + +x = ( +

+ Use the Button's +

+); + +this_really_should_split_across_lines = ( +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + after{stuff}after +
+); + +let myDiv = ReactTestUtils.renderIntoDocument( +
+
, +
+
, +); diff --git a/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.snap b/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.snap new file mode 100644 index 00000000000..03eb8021691 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.snap @@ -0,0 +1,1390 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: jsx/text-wrap/test.js +--- + +# Input + +```js +// Wrapping text +x = +
+ Some text that would need to wrap on to a new line in order to display correctly and nicely +
+ +// Wrapping tags +x = +
+ f f f f f f +
+ +// Wrapping tags +x = +
+ ffffff +
+ +// Wrapping tags +x = +
+ +// Wrapping tags +x = +
+ f +
+ +x = +
+ before
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at mollis lorem.
after +
+ +x = +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}{stuff}{stuff}after{stuff}after +
+ +x = +
+ before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after {stuff} {stuff} {stuff} after {stuff} after +
+ +x = +
+ Please state your name and occupation for the board of school directors. +
+ +function DiffOverview(props) { + const { source, target, since } = props; + return ( +
+
+

+ This diff overview is computed against the current list of records in + this collection and the list it contained on {humanDate(since)}. +

+

+ Note: last_modified and schema record metadata + are omitted for easier review. +

+
+ +
+ ); +} + +x = Starting at minute {graphActivity.startTime}, running for {graphActivity.length} to minute {graphActivity.startTime + graphActivity.length} + +x = +
+ First second third +
Something
+
+ +x = +
+
+ First +
+ Second +
+ Third +
+
+ +x = +
+ First
+ Second +
Third +
+ +leading_whitespace = +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +trailing_whitespace = +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +no_leading_or_trailing_whitespace = +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +facebook_translation_leave_text_around_tag = +
+ + First + , + ( + Second + ) +
+ +x = +
+ + First second third fourth fifth sixth seventh + , + ( + Second + ) +
+ +this_really_should_split_across_lines = +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after +
+ +unstable_before = +
+ Your score: {`${mini.crosstable.users[sessionUserId]} - ${mini.crosstable.users[user.id]}`} +
+ +unstable_after_first_run = ( +
+ Your score:{" "} + {`${mini.crosstable.users[sessionUserId]} - ${mini + .crosstable.users[user.id]}`} +
+); + +solitary_whitespace = +
+ +jsx_whitespace_on_newline = +
+
+ First +
+ Second +
+ Third +
+
+ +jsx_around_multiline_element = +
Before
{"Enough text to make this element wrap on to multiple lines when formatting"}
After
+ +jsx_around_multiline_element_second_pass = ( +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
{" "} + After +
+); + +convert_space_expressions = +
{" "}
+ +x = +
+ + + + + + +
+ +const Abc = () => { + return ( +
+ Please state your + {" "} + name + {" "} + and + {" "} + occupation + {" "} + for the board of directors. +
+ ); +}; + +x =
Some stuff here
+ +headers_and_paragraphs = ( +
+

First

+

The first paragraph.

+ +

Second

+

The second paragraph.

+
+); + +no_text_one_tag_per_line = +
+ +
+ +with_text_fill_line = +
+ Text +
+ +line_after_br = +
+ Text
+ More text
+ And more
+
+ +line_after_br = +
+ Text
More text
And more
+
+ +line_after_br = +
+ Text +
+ More text +
+ And more +
+
+ +line_after_br_2 =
A
B
C
+ +br_followed_by_whitespace =

text
+ +dont_preserve_blank_lines_when_jsx_contains_text = +
+ +
Zeroth
+ +
First
+ + Second + +
+ +multiple_expressions = +
+ {header} + {body} + {footer} +
+ +single_expression_child_tags = +
+ You currently have {dashboardStr} and {userStr} +
+ +expression_does_not_break = +
texty text text text text text text text text text text text {this.props.type}
+ +// FIXME +br_triggers_expression_break = +

+ text text text text text text text text text text text {this.props.type}
+ +jsx_whitespace_after_tag = +
+ + {variable} + + {" "} + ({variable}) +
+ +x = +
+ ENDS IN
+ text text text text text text text text text text text +
{" "} + HRS +
+ +x = +
+

Message

+ Hello, I'm a simple message. +
+ +x = +
+ Hello, I'm a simple message. +

Message

+
+ +x = +
+
+
+
+
+ Line {startRange.row + 1}:{startRange.column + 1} - {endRange.row + 1}:{endRange.column + 1}{caller} +
+
+
+
+
+ +x = +
+ {" "}
text
+
+ +// NOTE: Multiple JSX whitespaces are collapsed into a single space. +x = +
+ {" "}{" "}{" "} +
+ +// Don't break a self-closing element without attributes +// ---------- +x = +

+ text text text text text text text text text text text text text text text
text text text text text text +

; + +x = +
+
+ First +
- +
+ Second +
+
+ +x = +
+
+ First +
+ - +
+ Second +
+
+ +x = +
+
First
-
Second
+
+ +x = +
+
+ First +
- +
+ Second +
+
+ +x = +
+
+ First +
+ - +
+ Second +
+
+ +x = +
+
First
-
Second
+
+ +x = +
+ {hour}:{minute}:{second} +
+ +x = +
+ {hour} + : + {minute} + : + {second} +
+ +x = +
+ {hour}: + {minute}: + {second} +
+ +x =
text here.
+ +x =
Sales tax estimated using a rate of {salesTax * 100}%.
+ +x =
+ {title}  +
+ +x =
bar
+ +x =
+ + {name}’s{' '} + + Hello world.
+ You {type}ed this shipment to +
+ +x = + {parameter.Description}: {errorMsg} + + +x = + +x = Copy "{name}" + +x = (avg. {value}/5) + +x =

+ Use the Button's +

; + +this_really_should_split_across_lines = +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after +
+ +let myDiv = ReactTestUtils.renderIntoDocument( +
+ + ); + + // Wrapping tags + x = ( +
+- {" "} ++ + f +
+ ); +@@ -66,15 +69,19 @@ + + x = ( +
+- before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after{" "} +- {stuff} {stuff} {stuff} after {stuff} after ++ before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after { ++ stuff ++ } ++ {stuff} {stuff} after {stuff} after +
+ ); + + x = ( +
+- Please state your name and occupation for the board of{" "} +- school directors. ++ Please state your name and occupation for the board of ++ school ++ ++ directors. +
+ ); + +@@ -101,9 +108,10 @@ + x = ( + + +- Starting at minute {graphActivity.startTime}, running for{" "} +- {graphActivity.length} to minute{" "} +- {graphActivity.startTime + graphActivity.length} ++ Starting at minute {graphActivity.startTime}, running for { ++ graphActivity.length ++ } ++ to minute {graphActivity.startTime + graphActivity.length} + + + ); +@@ -176,19 +184,17 @@ + + unstable_before = ( +
+- Your score:{" "} +- {`${mini.crosstable.users[sessionUserId]} - ${ +- mini.crosstable.users[user.id] +- }`} ++ Your score: {`${ ++ mini.crosstable.users[sessionUserId] ++ } - ${mini.crosstable.users[user.id]}`} +
+ ); + + unstable_after_first_run = ( +
+- Your score:{" "} +- {`${mini.crosstable.users[sessionUserId]} - ${ +- mini.crosstable.users[user.id] +- }`} ++ Your score: {`${ ++ mini.crosstable.users[sessionUserId] ++ } - ${mini.crosstable.users[user.id]}`} +
+ ); + +@@ -213,24 +219,22 @@ + + jsx_around_multiline_element = ( +
+- Before{" "} +-
++ Before
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +-
{" "} ++
+ After +
+ ); + + jsx_around_multiline_element_second_pass = ( +
+- Before{" "} +-
++ Before
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +-
{" "} ++
+ After +
+ ); +@@ -251,8 +255,11 @@ + const Abc = () => { + return ( +
+- Please state your name and occupation for the board of +- directors. ++ Please state your ++ {" "}name ++ and ++ {" "}occupation ++ for the board of directors. +
+ ); + }; +@@ -318,19 +325,25 @@ + + line_after_br_2 = ( +
+- A
B
C ++ A ++
++ B ++
++ C +
+ ); + + br_followed_by_whitespace = ( +
+-
text ++
++ text +
+ ); + + dont_preserve_blank_lines_when_jsx_contains_text = ( +
+
Zeroth
++ +
First
+ Second +
+@@ -346,15 +359,18 @@ + + single_expression_child_tags = ( +
+- You currently have {dashboardStr} and{" "} +- {userStr} ++ You currently have {dashboardStr} and ++ {userStr} ++ +
+ ); + + expression_does_not_break = ( +
+- texty text text text text text text text text text text text{" "} +- {this.props.type}{" "} ++ texty text text text text text text text text text text text { ++ this.props.type ++ } ++ {" "} +
+ ); + +@@ -362,9 +378,8 @@ + br_triggers_expression_break = ( +
+
+- text text text text text text text text text text text { +- this.props.type +- }{" "} ++ text text text text text text text text text text text {this.props.type} ++ {" "} +
+ ); + +@@ -372,14 +387,14 @@ +
+ + {variable} +- {" "} ++ + ({variable}) +
+ ); + + x = ( +
+- ENDS IN
text text text text text text text text text text text
{" "} ++ ENDS IN
text text text text text text text text text text text
+ HRS +
+ ); +@@ -404,8 +419,9 @@ +
+
+
+- Line {startRange.row + 1}:{startRange.column + 1} -{" "} +- {endRange.row + 1}:{endRange.column + 1} ++ Line {startRange.row + 1}:{startRange.column + 1} - {endRange.row + ++ 1} ++ :{endRange.column + 1} + {caller} +
+
+@@ -436,13 +452,16 @@ + + x = ( +
+-
First
-
Second
++
First
- ++
Second
+
+ ); + + x = ( +
+-
First
-
Second
++
First
++ - ++
Second
+
+ ); + +@@ -496,19 +515,26 @@ + + x = ( +
+- {hour}:{minute}:{second} ++ {hour} ++ : ++ {minute} ++ : ++ {second} +
+ ); + + x = ( +
+- {hour}:{minute}:{second} ++ {hour}: ++ {minute}: ++ {second} +
+ ); + + x = ( +
+- text here.
++ text here. ++
+
+ ); + +@@ -528,7 +554,8 @@ + + {name}’s{" "} + +- Hello world.
++ Hello world. ++
+ You {type}ed this shipment to +
+ ); +@@ -564,7 +591,8 @@ + + let myDiv = ReactTestUtils.renderIntoDocument( +
+-
, ++
++ , +
+
, + ); +``` + +# Output + +```js +// Wrapping text +x = ( +
+ Some text that would need to wrap on to a new line in order to display + correctly and nicely +
+); + +// Wrapping tags +x = ( +
+ f f f f + f + + f +
+); + +// Wrapping tags +x = ( +
+ f + f + f + f + f + f +
+); + +// Wrapping tags +x = ( +
+); + +// Wrapping tags +x = ( +
+ + f +
+); + +x = ( +
+ before +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at + mollis lorem. +
+ after +
+); + +x = ( +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + {stuff} + {stuff}after{stuff}after +
+); + +x = ( +
+ before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after { + stuff + } + {stuff} {stuff} after {stuff} after +
+); + +x = ( +
+ Please state your name and occupation for the board of + school + + directors. +
+); + +function DiffOverview(props) { + const { source, target, since } = props; + return ( +
+
+

+ This diff overview is computed against the current list of records in + this collection and the list it contained on {humanDate(since)} + . +

+

+ Note: last_modified and schema record + metadata are omitted for easier review. +

+
+ +
+ ); +} + +x = ( + + + Starting at minute {graphActivity.startTime}, running for { + graphActivity.length + } + to minute {graphActivity.startTime + graphActivity.length} + + +); + +x = ( +
+ First second third +
+ Something +
+
+); + +x = ( +
+
First
+ Second +
Third
+
+); + +x = ( +
+ First
Second
Third +
+); + +leading_whitespace = ( +
+ {" "} + First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh + Twelfth Thirteenth Fourteenth +
+); + +trailing_whitespace = ( +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh + Twelfth Thirteenth Fourteenth{" "} +
+); + +no_leading_or_trailing_whitespace = ( +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh + Twelfth Thirteenth Fourteenth +
+); + +facebook_translation_leave_text_around_tag = ( +
+ First, (Second) +
+); + +x = ( +
+ First second third fourth fifth sixth seventh, ( + Second) +
+); + +this_really_should_split_across_lines = ( +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + after{stuff}after{stuff}after +
+); + +unstable_before = ( +
+ Your score: {`${ + mini.crosstable.users[sessionUserId] + } - ${mini.crosstable.users[user.id]}`} +
+); + +unstable_after_first_run = ( +
+ Your score: {`${ + mini.crosstable.users[sessionUserId] + } - ${mini.crosstable.users[user.id]}`} +
+); + +solitary_whitespace = ( +
+ {" "} +
+); + +jsx_whitespace_on_newline = ( +
+
First
Second
Third
+
+); + +jsx_around_multiline_element = ( +
+ Before
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
+ After +
+); + +jsx_around_multiline_element_second_pass = ( +
+ Before
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
+ After +
+); + +convert_space_expressions =
; + +x = ( +
+ + + + + + +
+); + +const Abc = () => { + return ( +
+ Please state your + {" "}name + and + {" "}occupation + for the board of directors. +
+ ); +}; + +x =
Some stuff here
; + +headers_and_paragraphs = ( +
+

First

+

The first paragraph.

+ +

Second

+

The second paragraph.

+
+); + +no_text_one_tag_per_line = ( +
+ + +
+); + +with_text_fill_line = ( +
+ Text + +
+); + +line_after_br = ( +
+ Text +
+ More text +
+ And more +
+
+); + +line_after_br = ( +
+ Text +
+ More text +
+ And more +
+
+); + +line_after_br = ( +
+ Text +
+ More text +
+ And more +
+
+); + +line_after_br_2 = ( +
+ A +
+ B +
+ C +
+); + +br_followed_by_whitespace = ( +
+
+ text +
+); + +dont_preserve_blank_lines_when_jsx_contains_text = ( +
+
Zeroth
+ +
First
+ Second +
+); + +multiple_expressions = ( +
+ {header} + {body} + {footer} +
+); + +single_expression_child_tags = ( +
+ You currently have {dashboardStr} and + {userStr} + +
+); + +expression_does_not_break = ( +
+ texty text text text text text text text text text text text { + this.props.type + } + {" "} +
+); + +// FIXME +br_triggers_expression_break = ( +
+
+ text text text text text text text text text text text {this.props.type} + {" "} +
+); + +jsx_whitespace_after_tag = ( +
+ + {variable} + + ({variable}) +
+); + +x = ( +
+ ENDS IN
text text text text text text text text text text text
+ HRS +
+); + +x = ( +
+

Message

+ Hello, I'm a simple message. +
+); + +x = ( +
+ Hello, I'm a simple message. +

Message

+
+); + +x = ( +
+
+
+
+
+ Line {startRange.row + 1}:{startRange.column + 1} - {endRange.row + + 1} + :{endRange.column + 1} + {caller} +
+
+
+
+
+); + +x = ( +
+ {" "} +
text
+
+); + +// NOTE: Multiple JSX whitespaces are collapsed into a single space. +x =
; + +// Don't break a self-closing element without attributes +// ---------- +x = ( +

+ text text text text text text text text text text text text text text text +
+ text text text text text text +

+); + +x = ( +
+
First
- +
Second
+
+); + +x = ( +
+
First
+ - +
Second
+
+); + +x = ( +
+
First
-
Second
+
+); + +x = ( +
+
+ First +
+ - +
+ Second +
+
+); + +x = ( +
+
+ First +
+ - +
+ Second +
+
+); + +x = ( +
+
+ First +
+ - +
+ Second +
+
+); + +x = ( +
+ {hour}:{minute}:{second} +
+); + +x = ( +
+ {hour} + : + {minute} + : + {second} +
+); + +x = ( +
+ {hour}: + {minute}: + {second} +
+); + +x = ( +
+ text here. +
+
+); + +x =
Sales tax estimated using a rate of {salesTax * 100}%.
; + +x =
{title} 
; + +x = ( +
+ + bar +
+); + +x = ( +
+ + {name}’s{" "} + + Hello world. +
+ You {type}ed this shipment to +
+); + +x = ( + + {parameter.Description}: {errorMsg} + +); + +x = ( + +); + +x = Copy "{name}"; + +x = (avg. {value}/5); + +x = ( +

+ Use the Button's +

+); + +this_really_should_split_across_lines = ( +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff} + after{stuff}after +
+); + +let myDiv = ReactTestUtils.renderIntoDocument( +
+
+ , +
+
, +); +``` + + +# Lines exceeding max width of 80 characters +``` + 72: before {stuff} after {stuff} after {stuff} after {stuff} after {stuff} after { + 122:
+ 224: "Enough text to make this element wrap on to multiple lines when formatting" + 235: "Enough text to make this element wrap on to multiple lines when formatting" +``` + diff --git a/crates/rome_js_formatter/tests/specs/prettier/prepare_tests.js b/crates/rome_js_formatter/tests/specs/prettier/prepare_tests.js index 288ca96c300..9840ae0e75e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/prepare_tests.js +++ b/crates/rome_js_formatter/tests/specs/prettier/prepare_tests.js @@ -78,6 +78,7 @@ async function traverseDir(dir, config) { } const PRETTIER_ROOT_JS = path.resolve(PRETTIER_ROOT, "js"); +const PRETTIER_ROOT_JSX = path.resolve(PRETTIER_ROOT, "jsx"); const PRETTIER_ROOT_TS = path.resolve(PRETTIER_ROOT, "typescript"); const defaultConfig = { @@ -94,6 +95,13 @@ async function main() { ...defaultConfig, parser: "babel", }); + + console.log("Extracting tests from %s ...", {PRETTIER_ROOT_JSX}); + await traverseDir(PRETTIER_ROOT_JSX, { + ...defaultConfig, + parser: "babel", + }); + console.log("Extracting tests from %s ...", PRETTIER_ROOT_TS); await traverseDir(PRETTIER_ROOT_TS, { ...defaultConfig, diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts new file mode 100644 index 00000000000..de1ccb2859a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts @@ -0,0 +1 @@ +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts.prettier-snap new file mode 100644 index 00000000000..de1ccb2859a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/conditional-types/issue-13275.ts.prettier-snap @@ -0,0 +1 @@ +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.prettier-snap index ba48c56ec74..7ba227a2b2c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.prettier-snap @@ -1,13 +1,13 @@ enum A { - [i++], + i++, } const bar = "bar"; enum B { - [bar] = 2, + bar = 2, } const foo = () => "foo"; enum C { - [foo()] = 2, + foo() = 2, } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.snap index 0f789d4cf8d..3c1443ded3f 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/enum/computed-members.ts.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/enum/computed-members.ts --- # Input @@ -28,19 +30,19 @@ enum C { +++ Rome @@ -1,13 +1,7 @@ -enum A { -- [i++], +- i++, -} +enum A { [i++] } const bar = "bar"; -enum B { -- [bar] = 2, +- bar = 2, -} +enum B { [bar] = 2 } const foo = () => "foo"; -enum C { -- [foo()] = 2, +- foo() = 2, -} +enum C { [foo()] = 2 } ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.prettier-snap index 7751d7a4192..fd8cf153040 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.prettier-snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.prettier-snap @@ -1,8 +1,8 @@ let a: *; function b(x: ?) {} let c: ?string; -let d: string?; +let d: ?string; let e: ?(string | number); let f: !string; -let g: string!; +let g: !string; let h: !(string | number); diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.snap index bc35ce5fc7d..7f845c09a23 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/error-recovery/jsdoc_only_types.ts.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/error-recovery/jsdoc_only_types.ts --- # Input @@ -27,10 +29,10 @@ let h: !(string | number); +* function b(x: ?) {} -let c: ?string; --let d: string?; +-let d: ?string; -let e: ?(string | number); -let f: !string; --let g: string!; +-let g: !string; -let h: !(string | number); +let c: +?string diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts index 579bb27c4f3..3bf95b1df83 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts @@ -1,7 +1,7 @@ export interface Environment1 extends GenericEnvironment< SomeType, AnotherType, - YetAnotherType + YetAnotherType, > { m(): void; }; @@ -12,7 +12,7 @@ export class Environment2 extends GenericEnvironment< DifferentType1, DifferentType2, DifferentType3, - DifferentType4 + DifferentType4, > { m() {}; }; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts.snap index 0aafee6722c..5104cc03914 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/interface2/break.ts.snap @@ -1,5 +1,7 @@ --- source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/interface2/break.ts --- # Input @@ -8,7 +10,7 @@ source: crates/rome_js_formatter/tests/prettier_tests.rs export interface Environment1 extends GenericEnvironment< SomeType, AnotherType, - YetAnotherType + YetAnotherType, > { m(): void; }; @@ -19,7 +21,7 @@ export class Environment2 extends GenericEnvironment< DifferentType1, DifferentType2, DifferentType3, - DifferentType4 + DifferentType4, > { m() {}; }; @@ -79,7 +81,30 @@ export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTyp ```diff --- Prettier +++ Rome -@@ -68,14 +68,14 @@ +@@ -1,5 +1,8 @@ +-export interface Environment1 +- extends GenericEnvironment { ++export interface Environment1 extends GenericEnvironment< ++ SomeType, ++ AnotherType, ++ YetAnotherType, ++> { + m(): void; + } + export class Environment2 extends GenericEnvironment< +@@ -9,9 +12,9 @@ + DifferentType1, + DifferentType2, + DifferentType3, +- DifferentType4 ++ DifferentType4, + > { +- m() {} ++ m() {}; + } + + // Declare Interface Break +@@ -68,14 +71,14 @@ interface ExtendsMany extends ASingleGenericInterface< @@ -102,7 +127,7 @@ export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTyp x: string; } -@@ -97,6 +97,6 @@ +@@ -97,6 +100,6 @@ export interface ExtendsLongOneWithGenerics extends Bar< @@ -117,8 +142,11 @@ export interface ExtendsLongOneWithGenerics extends Bar< SomeLongTypeSomeLongTyp # Output ```js -export interface Environment1 - extends GenericEnvironment { +export interface Environment1 extends GenericEnvironment< + SomeType, + AnotherType, + YetAnotherType, +> { m(): void; } export class Environment2 extends GenericEnvironment< @@ -128,9 +156,9 @@ export class Environment2 extends GenericEnvironment< DifferentType1, DifferentType2, DifferentType3, - DifferentType4 + DifferentType4, > { - m() {} + m() {}; } // Declare Interface Break @@ -222,4 +250,21 @@ export interface ExtendsLongOneWithGenerics ``` +# Errors +``` +error[SyntaxError]: expected a type parameter but instead found '>' + ┌─ break.ts:5:1 + │ +5 │ > { + │ ^ Expected a type parameter here + +error[SyntaxError]: expected a type parameter but instead found '>' + ┌─ break.ts:16:1 + │ +16 │ > { + │ ^ Expected a type parameter here + + +``` + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts new file mode 100644 index 00000000000..22648828e01 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts @@ -0,0 +1,6 @@ +type loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.prettier-snap new file mode 100644 index 00000000000..73c3e12f412 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.prettier-snap @@ -0,0 +1,7 @@ +type loremIpsumFooBazBar1 = "Multiline string\ + Multiline string"; + +type loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.snap new file mode 100644 index 00000000000..553bece6606 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/literal/multiline.ts.snap @@ -0,0 +1,47 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/literal/multiline.ts +--- + +# Input + +```js +type loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,7 +1,6 @@ + type loremIpsumFooBazBar1 = "Multiline string\ + Multiline string"; + +-type loremIpsumFooBazBar2 = +- "Multiline string\ ++type loremIpsumFooBazBar2 = "Multiline string\ + Multiline string\ + Multiline string"; +``` + +# Output + +```js +type loremIpsumFooBazBar1 = "Multiline string\ + Multiline string"; + +type loremIpsumFooBazBar2 = "Multiline string\ + Multiline string\ + Multiline string"; +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts new file mode 100644 index 00000000000..e10c347fb64 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts @@ -0,0 +1,6 @@ +// https://github.com/typescript-eslint/typescript-eslint/pull/4382 +function decorator() {} +@decorator +class Foo { + bar(baz: typeof this) {} +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.prettier-snap new file mode 100644 index 00000000000..e10c347fb64 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.prettier-snap @@ -0,0 +1,6 @@ +// https://github.com/typescript-eslint/typescript-eslint/pull/4382 +function decorator() {} +@decorator +class Foo { + bar(baz: typeof this) {} +} diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.snap new file mode 100644 index 00000000000..e9c459e11a2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/decorators.ts.snap @@ -0,0 +1,46 @@ +--- +source: crates/rome_js_formatter/tests/prettier_tests.rs +info: + test_file: typescript/typeof-this/decorators.ts +--- + +# Input + +```js +// https://github.com/typescript-eslint/typescript-eslint/pull/4382 +function decorator() {} +@decorator +class Foo { + bar(baz: typeof this) {} +} +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Rome +@@ -1,5 +1,6 @@ + // https://github.com/typescript-eslint/typescript-eslint/pull/4382 + function decorator() {} ++ + @decorator + class Foo { + bar(baz: typeof this) {} +``` + +# Output + +```js +// https://github.com/typescript-eslint/typescript-eslint/pull/4382 +function decorator() {} + +@decorator +class Foo { + bar(baz: typeof this) {} +} +``` + + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts new file mode 100644 index 00000000000..7f3c4f11d4c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts @@ -0,0 +1,3 @@ +// https://github.com/typescript-eslint/typescript-eslint/pull/4382 +let self: typeof this; +let foo: typeof this.foo; diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts.prettier-snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts.prettier-snap new file mode 100644 index 00000000000..7f3c4f11d4c --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/typeof-this/typeof-this.ts.prettier-snap @@ -0,0 +1,3 @@ +// https://github.com/typescript-eslint/typescript-eslint/pull/4382 +let self: typeof this; +let foo: typeof this.foo;