From 380a55b64f8a8b1996a5c119cc275979fa4ee579 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 19 Sep 2022 17:10:44 +0200 Subject: [PATCH] test(rome_js_formatter): Add prettier JSX tests This PR extracts the JSX tests from prettier and updates existing tests. There are a few instability issues, most related to comments. I'll look into those as part of the comments refactoring --- .../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 +- .../tests/specs/prettier/js/record/spread.js | 1 - .../specs/prettier/js/record/spread.js.snap | 3 +- .../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/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 ++++ .../specs/prettier/jsx/fragment/fragment.js | 72 +++ .../jsx/fragment/fragment.js.prettier-snap | 72 +++ .../specs/prettier/jsx/ignore/jsx_ignore.js | 56 ++ .../jsx/ignore/jsx_ignore.js.prettier-snap | 55 ++ .../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/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 ++++ .../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 ++++++ .../specs/prettier/jsx/spread/attribute.js | 25 + .../jsx/spread/attribute.js.prettier-snap | 36 ++ .../tests/specs/prettier/jsx/spread/child.js | 23 + .../jsx/spread/child.js.prettier-snap | 32 + .../prettier/jsx/stateless-arrow-fn/test.js | 73 +++ .../stateless-arrow-fn/test.js.prettier-snap | 170 ++++++ .../jsx/template/styled-components.js | 18 + .../styled-components.js.prettier-snap | 19 + .../specs/prettier/jsx/text-wrap/test.js | 458 ++++++++++++++ .../jsx/text-wrap/test.js.prettier-snap | 570 ++++++++++++++++++ .../tests/specs/prettier/prepare_tests.js | 8 + .../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 +- 60 files changed, 2893 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/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/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/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/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/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/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/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/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/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/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/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/text-wrap/test.js create mode 100644 crates/rome_js_formatter/tests/specs/prettier/jsx/text-wrap/test.js.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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 + + +``` +