diff --git a/tests/config/run-format-test.js b/tests/config/run-format-test.js index 8f1eebe9f..d4faab81f 100644 --- a/tests/config/run-format-test.js +++ b/tests/config/run-format-test.js @@ -108,6 +108,9 @@ const hermesDisabledTests = new Set([ // Not supported "flow/comments", "flow-repo/union_new", + + // Different result + "flow/hook/comments-before-arrow.js", ].map((file) => path.join(__dirname, "../format", file)), ]); const flowDisabledTests = new Set( diff --git a/tests/format/flow/hook/__snapshots__/format.test.js.snap b/tests/format/flow/hook/__snapshots__/format.test.js.snap index be2fc7195..0f6c584a0 100644 --- a/tests/format/flow/hook/__snapshots__/format.test.js.snap +++ b/tests/format/flow/hook/__snapshots__/format.test.js.snap @@ -1,5 +1,67 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +exports[`comments-before-arrow.js format 1`] = ` +====================================options===================================== +parsers: ["flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +/* +The following should format like \`ArrowFunctionExpression\`, +but currently the AST shape are different, and it allows line break before \`=>\` + +This is valid + +\`\`\` +type A1 = hook () /* +1 *\\/ => void +\`\`\` + +while this is invalid + +\`\`\` +a = () /* +1 *\\/ => void +\`\`\` +*/ +type A1 = hook /* 11 */ () => void +type A2 = hook () /* 12 */ => void +type A3 = hook () => /* 13 */ void + +a = /* 21 */ () => {} +a = () /* 22 */ => {} +a = () => /* 23 */ {} + +=====================================output===================================== +/* +The following should format like \`ArrowFunctionExpression\`, +but currently the AST shape are different, and it allows line break before \`=>\` + +This is valid + +\`\`\` +type A1 = hook () /* +1 *\\/ => void +\`\`\` + +while this is invalid + +\`\`\` +a = () /* +1 *\\/ => void +\`\`\` +*/ +type A1 = hook () => /* 11 */ void; +type A2 = hook () => /* 12 */ void; +type A3 = hook () => /* 13 */ void; + +a = /* 21 */ () => {}; +a = () /* 22 */ => {}; +a = () => /* 23 */ {}; + +================================================================================ +`; + exports[`dangling-comments.js format 1`] = ` ====================================options===================================== parsers: ["flow"] diff --git a/tests/format/flow/hook/comments-before-arrow.js b/tests/format/flow/hook/comments-before-arrow.js new file mode 100644 index 000000000..05559faf9 --- /dev/null +++ b/tests/format/flow/hook/comments-before-arrow.js @@ -0,0 +1,25 @@ +/* +The following should format like `ArrowFunctionExpression`, +but currently the AST shape are different, and it allows line break before `=>` + +This is valid + +``` +type A1 = hook () /* +1 *\/ => void +``` + +while this is invalid + +``` +a = () /* +1 *\/ => void +``` +*/ +type A1 = hook /* 11 */ () => void +type A2 = hook () /* 12 */ => void +type A3 = hook () => /* 13 */ void + +a = /* 21 */ () => {} +a = () /* 22 */ => {} +a = () => /* 23 */ {}