diff --git a/tests/config/format-test/failed-format-tests.js b/tests/config/format-test/failed-format-tests.js index 25c076e39..625c6a413 100644 --- a/tests/config/format-test/failed-format-tests.js +++ b/tests/config/format-test/failed-format-tests.js @@ -85,12 +85,11 @@ const disabledTests = new Map( "typescript/module/module_nested.ts", "typescript/custom/stability/moduleBlock.ts", "typescript/interface2/module.ts", - "typescript/typescript-only/", ], oxc: [], - "oxc-ts": ["typescript/typescript-only/"], - yuku: [], - "yuku-ts": ["typescript/typescript-only/"], + "oxc-ts": [], + yuku: ["js/await/await-with-parens.js"], + "yuku-ts": ["js/await/await-with-parens.js"], hermes: [ ...commentClosureTypecaseTests, @@ -100,10 +99,12 @@ const disabledTests = new Map( // Different result "flow/hook/comments-before-arrow.js", + "js/await/like-call.js", ], flow: [ - // Parsing to different ASTs - "js/decorators/member-expression.js", + "js/decorators/member-expression.js", // Parsing to different ASTs + "js/await/await-with-parens.js", + "js/await/like-call.js", ], typescript: [ // https://github.com/typescript-eslint/typescript-eslint/issues/11389 diff --git a/tests/format/js/await/__snapshots__/format.test.js.snap b/tests/format/js/await/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..02fd520b3 --- /dev/null +++ b/tests/format/js/await/__snapshots__/format.test.js.snap @@ -0,0 +1,98 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`await-with-parens.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] + printWidth: 80 (default) | +=====================================input====================================== +function foo(promise) { await (promise); } + +function a() { + return await (1) +} + +() => { await (x) }; + +function foo2() { + await + (foo); +} + +export class C { + p = await (0); +} + +await (0); + +=====================================output===================================== +function foo(promise) { + await(promise); +} + +function a() { + return await(1); +} + +() => { + await(x); +}; + +function foo2() { + await(foo); +} + +export class C { + p = await(0); +} + +await 0; + +================================================================================ +`; + +exports[`await-with-parens.js format[espree] 1`] = ` +"Cannot use keyword 'await' outside an async function (1:25) +> 1 | function foo(promise) { await (promise); } + | ^ + 2 | + 3 | function a() { + 4 | return await (1) +Cause: Cannot use keyword 'await' outside an async function" +`; + +exports[`await-with-parens.js format[hermes] 1`] = ` +"'await' not in an async function (15:7) + 13 | + 14 | export class C { +> 15 | p = await (0); + | ^ + 16 | } + 17 | + 18 | await (0); +Cause: 'await' not in an async function (15:6) + p = await (0); + ^~~~~~~~~" +`; + +exports[`await-with-parens.js format[meriyah] 1`] = ` +"Await is only valid in async functions (1:25) +> 1 | function foo(promise) { await (promise); } + | ^^^^^ + 2 | + 3 | function a() { + 4 | return await (1) +Cause: [1:24-1:29]: Await is only valid in async functions" +`; + +exports[`like-call.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] + printWidth: 80 (default) | +=====================================input====================================== +await (1) + +=====================================output===================================== +await 1; + +================================================================================ +`; diff --git a/tests/format/typescript/typescript-only/await-with-parens.ts b/tests/format/js/await/await-with-parens.js similarity index 90% rename from tests/format/typescript/typescript-only/await-with-parens.ts rename to tests/format/js/await/await-with-parens.js index a13cfda42..301a97b3b 100644 --- a/tests/format/typescript/typescript-only/await-with-parens.ts +++ b/tests/format/js/await/await-with-parens.js @@ -6,7 +6,7 @@ function a() { () => { await (x) }; -function foo() { +function foo2() { await (foo); } diff --git a/tests/format/js/await/format.test.js b/tests/format/js/await/format.test.js new file mode 100644 index 000000000..a499c6d6c --- /dev/null +++ b/tests/format/js/await/format.test.js @@ -0,0 +1,7 @@ +runFormatTest(import.meta, ["babel", "flow", "typescript"], { + errors: { + hermes: ["await-with-parens.js"], + meriyah: ["await-with-parens.js"], + espree: ["await-with-parens.js"], + }, +}); diff --git a/tests/format/js/await/like-call.js b/tests/format/js/await/like-call.js new file mode 100644 index 000000000..67d48ac47 --- /dev/null +++ b/tests/format/js/await/like-call.js @@ -0,0 +1 @@ +await (1) diff --git a/tests/format/typescript/decorator-auto-accessors/__snapshots__/format.test.js.snap b/tests/format/typescript/decorator-auto-accessors/__snapshots__/format.test.js.snap index dc0645bcb..2efe2dedc 100644 --- a/tests/format/typescript/decorator-auto-accessors/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/decorator-auto-accessors/__snapshots__/format.test.js.snap @@ -1,5 +1,135 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +exports[`decorator-auto-accessors-abstract-class.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] + printWidth: 80 (default) | +=====================================input====================================== +abstract class Foo { + declare accessor prop7: number; + private accessor #p: any; + + abstract accessor #s; + accessor #d?; + abstract accessor f; + readonly accessor g; +} + +=====================================output===================================== +abstract class Foo { + declare accessor prop7: number; + private accessor #p: any; + + abstract accessor #s; + accessor #d?; + abstract accessor f; + readonly accessor g; +} + +================================================================================ +`; + +exports[`decorator-auto-accessors-abstract-class.ts format[babel-ts] 1`] = ` +"An 'accessor' property cannot be declared optional. (6:3) + 4 | + 5 | abstract accessor #s; +> 6 | accessor #d?; + | ^ + 7 | abstract accessor f; + 8 | readonly accessor g; + 9 | } +Cause: An 'accessor' property cannot be declared optional. (6:2)" +`; + +exports[`decorator-auto-accessors-abstract-class.ts format[oxc-ts] 1`] = ` +"'accessor' modifier cannot be used with 'declare' modifier. (2:3) + 1 | abstract class Foo { +> 2 | declare accessor prop7: number; + | ^^^^^^^ + 3 | private accessor #p: any; + 4 | + 5 | abstract accessor #s;" +`; + +exports[`decorator-auto-accessors-declare-class.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] + printWidth: 80 (default) | +=====================================input====================================== +declare class C { + accessor x = 1; + #y = 1; +} + +=====================================output===================================== +declare class C { + accessor x = 1; + #y = 1; +} + +================================================================================ +`; + +exports[`decorator-auto-accessors-declare-class.ts format[oxc-ts] 1`] = ` +"Initializers are not allowed in ambient contexts. (3:8) + 1 | declare class C { + 2 | accessor x = 1; +> 3 | #y = 1; + | ^ + 4 | } + 5 |" +`; + +exports[`decorator-auto-accessors-mixed-modifiers.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] + printWidth: 80 (default) | +=====================================input====================================== +abstract class Foo { + accessor prop: number = 1; + static accessor prop2: number = 1; + accessor #prop3: number = 1; + accessor [prop4]: number = 1; + private accessor prop5: number = 1; + abstract accessor prop6: number; + private accessor #p: any; + + accessor a!: any; + accessor aa!: any; + abstract accessor #s; + readonly accessor g; +} + +=====================================output===================================== +abstract class Foo { + accessor prop: number = 1; + static accessor prop2: number = 1; + accessor #prop3: number = 1; + accessor [prop4]: number = 1; + private accessor prop5: number = 1; + abstract accessor prop6: number; + private accessor #p: any; + + accessor a!: any; + accessor aa!: any; + abstract accessor #s; + readonly accessor g; +} + +================================================================================ +`; + +exports[`decorator-auto-accessors-mixed-modifiers.ts format[oxc-ts] 1`] = ` +"An accessibility modifier cannot be used with a private identifier. (8:3) + 6 | private accessor prop5: number = 1; + 7 | abstract accessor prop6: number; +> 8 | private accessor #p: any; + | ^^^^^^^ + 9 | + 10 | accessor a!: any; + 11 | accessor aa!: any;" +`; + exports[`decorator-auto-accessors-new-line.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/typescript-only/decorator-auto-accessors-abstract-class.ts b/tests/format/typescript/decorator-auto-accessors/decorator-auto-accessors-abstract-class.ts similarity index 100% rename from tests/format/typescript/typescript-only/decorator-auto-accessors-abstract-class.ts rename to tests/format/typescript/decorator-auto-accessors/decorator-auto-accessors-abstract-class.ts diff --git a/tests/format/typescript/typescript-only/decorator-auto-accessors-declara-class.ts b/tests/format/typescript/decorator-auto-accessors/decorator-auto-accessors-declare-class.ts similarity index 100% rename from tests/format/typescript/typescript-only/decorator-auto-accessors-declara-class.ts rename to tests/format/typescript/decorator-auto-accessors/decorator-auto-accessors-declare-class.ts diff --git a/tests/format/typescript/typescript-only/decorator-auto-accessors-mixed-modifiers.ts b/tests/format/typescript/decorator-auto-accessors/decorator-auto-accessors-mixed-modifiers.ts similarity index 100% rename from tests/format/typescript/typescript-only/decorator-auto-accessors-mixed-modifiers.ts rename to tests/format/typescript/decorator-auto-accessors/decorator-auto-accessors-mixed-modifiers.ts diff --git a/tests/format/typescript/decorator-auto-accessors/format.test.js b/tests/format/typescript/decorator-auto-accessors/format.test.js index 116dcbd78..4e5403d26 100644 --- a/tests/format/typescript/decorator-auto-accessors/format.test.js +++ b/tests/format/typescript/decorator-auto-accessors/format.test.js @@ -1 +1,10 @@ -runFormatTest(import.meta, ["typescript"]); +runFormatTest(import.meta, ["typescript"], { + errors: { + "babel-ts": ["decorator-auto-accessors-abstract-class.ts"], + "oxc-ts": [ + "decorator-auto-accessors-abstract-class.ts", + "decorator-auto-accessors-declare-class.ts", + "decorator-auto-accessors-mixed-modifiers.ts", + ], + }, +}); diff --git a/tests/format/typescript/prettier-ignore/no-semi/__snapshots__/format.test.js.snap b/tests/format/typescript/prettier-ignore/no-semi/__snapshots__/format.test.js.snap new file mode 100644 index 000000000..fc8d946a4 --- /dev/null +++ b/tests/format/typescript/prettier-ignore/no-semi/__snapshots__/format.test.js.snap @@ -0,0 +1,40 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`prettier-ignore-parenthesized-type.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +semi: false + printWidth: 80 (default) | +=====================================input====================================== +type Foo = + // prettier-ignore + ( + aa + ); + +=====================================output===================================== +type Foo = + // prettier-ignore + aa + +================================================================================ +`; + +exports[`prettier-ignore-parenthesized-type.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] + printWidth: 80 (default) | +=====================================input====================================== +type Foo = + // prettier-ignore + ( + aa + ); + +=====================================output===================================== +type Foo = + // prettier-ignore + aa; + +================================================================================ +`; diff --git a/tests/format/typescript/typescript-only/format.test.js b/tests/format/typescript/prettier-ignore/no-semi/format.test.js similarity index 100% rename from tests/format/typescript/typescript-only/format.test.js rename to tests/format/typescript/prettier-ignore/no-semi/format.test.js diff --git a/tests/format/typescript/typescript-only/prettier-ignore-parenthesized-type.ts b/tests/format/typescript/prettier-ignore/no-semi/prettier-ignore-parenthesized-type.ts similarity index 100% rename from tests/format/typescript/typescript-only/prettier-ignore-parenthesized-type.ts rename to tests/format/typescript/prettier-ignore/no-semi/prettier-ignore-parenthesized-type.ts diff --git a/tests/format/typescript/typescript-only/__snapshots__/format.test.js.snap b/tests/format/typescript/typescript-only/__snapshots__/format.test.js.snap deleted file mode 100644 index ce4862d09..000000000 --- a/tests/format/typescript/typescript-only/__snapshots__/format.test.js.snap +++ /dev/null @@ -1,388 +0,0 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing - -exports[`await-with-parens.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -function foo(promise) { await (promise); } - -function a() { - return await (1) -} - -() => { await (x) }; - -function foo() { - await - (foo); -} - -export class C { - p = await (0); -} - -await (0); - -=====================================output===================================== -function foo(promise) { - await(promise) -} - -function a() { - return await(1) -} - -;() => { - await(x) -} - -function foo() { - await(foo) -} - -export class C { - p = await(0) -} - -await 0 - -================================================================================ -`; - -exports[`await-with-parens.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -function foo(promise) { await (promise); } - -function a() { - return await (1) -} - -() => { await (x) }; - -function foo() { - await - (foo); -} - -export class C { - p = await (0); -} - -await (0); - -=====================================output===================================== -function foo(promise) { - await(promise); -} - -function a() { - return await(1); -} - -() => { - await(x); -}; - -function foo() { - await(foo); -} - -export class C { - p = await(0); -} - -await 0; - -================================================================================ -`; - -exports[`decorator-auto-accessors-abstract-class.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -abstract class Foo { - declare accessor prop7: number; - private accessor #p: any; - - abstract accessor #s; - accessor #d?; - abstract accessor f; - readonly accessor g; -} - -=====================================output===================================== -abstract class Foo { - declare accessor prop7: number - private accessor #p: any - - abstract accessor #s - accessor #d? - abstract accessor f - readonly accessor g -} - -================================================================================ -`; - -exports[`decorator-auto-accessors-abstract-class.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -abstract class Foo { - declare accessor prop7: number; - private accessor #p: any; - - abstract accessor #s; - accessor #d?; - abstract accessor f; - readonly accessor g; -} - -=====================================output===================================== -abstract class Foo { - declare accessor prop7: number; - private accessor #p: any; - - abstract accessor #s; - accessor #d?; - abstract accessor f; - readonly accessor g; -} - -================================================================================ -`; - -exports[`decorator-auto-accessors-declara-class.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -declare class C { - accessor x = 1; - #y = 1; -} - -=====================================output===================================== -declare class C { - accessor x = 1 - #y = 1 -} - -================================================================================ -`; - -exports[`decorator-auto-accessors-declara-class.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -declare class C { - accessor x = 1; - #y = 1; -} - -=====================================output===================================== -declare class C { - accessor x = 1; - #y = 1; -} - -================================================================================ -`; - -exports[`decorator-auto-accessors-mixed-modifiers.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -abstract class Foo { - accessor prop: number = 1; - static accessor prop2: number = 1; - accessor #prop3: number = 1; - accessor [prop4]: number = 1; - private accessor prop5: number = 1; - abstract accessor prop6: number; - private accessor #p: any; - - accessor a!: any; - accessor aa!: any; - abstract accessor #s; - readonly accessor g; -} - -=====================================output===================================== -abstract class Foo { - accessor prop: number = 1 - static accessor prop2: number = 1 - accessor #prop3: number = 1 - accessor [prop4]: number = 1 - private accessor prop5: number = 1 - abstract accessor prop6: number - private accessor #p: any - - accessor a!: any - accessor aa!: any - abstract accessor #s - readonly accessor g -} - -================================================================================ -`; - -exports[`decorator-auto-accessors-mixed-modifiers.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -abstract class Foo { - accessor prop: number = 1; - static accessor prop2: number = 1; - accessor #prop3: number = 1; - accessor [prop4]: number = 1; - private accessor prop5: number = 1; - abstract accessor prop6: number; - private accessor #p: any; - - accessor a!: any; - accessor aa!: any; - abstract accessor #s; - readonly accessor g; -} - -=====================================output===================================== -abstract class Foo { - accessor prop: number = 1; - static accessor prop2: number = 1; - accessor #prop3: number = 1; - accessor [prop4]: number = 1; - private accessor prop5: number = 1; - abstract accessor prop6: number; - private accessor #p: any; - - accessor a!: any; - accessor aa!: any; - abstract accessor #s; - readonly accessor g; -} - -================================================================================ -`; - -exports[`parenthesized-decorators-call-expression.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -@(test().x("global").y()) -class X {} - -=====================================output===================================== -@(test().x("global").y()) -class X {} - -================================================================================ -`; - -exports[`parenthesized-decorators-call-expression.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -@(test().x("global").y()) -class X {} - -=====================================output===================================== -@(test().x("global").y()) -class X {} - -================================================================================ -`; - -exports[`parenthesized-decorators-tagged-template.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -class Test { - @foo\`bar\` - text: string = "text" -} - -=====================================output===================================== -class Test { - @(foo\`bar\`) - text: string = "text" -} - -================================================================================ -`; - -exports[`parenthesized-decorators-tagged-template.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -class Test { - @foo\`bar\` - text: string = "text" -} - -=====================================output===================================== -class Test { - @(foo\`bar\`) - text: string = "text"; -} - -================================================================================ -`; - -exports[`prettier-ignore-parenthesized-type.ts - {"semi":false} format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -semi: false - printWidth: 80 (default) | -=====================================input====================================== -type Foo = - // prettier-ignore - ( - aa - ); - -=====================================output===================================== -type Foo = - // prettier-ignore - aa - -================================================================================ -`; - -exports[`prettier-ignore-parenthesized-type.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] - printWidth: 80 (default) | -=====================================input====================================== -type Foo = - // prettier-ignore - ( - aa - ); - -=====================================output===================================== -type Foo = - // prettier-ignore - aa; - -================================================================================ -`; diff --git a/tests/format/typescript/typescript-only/parenthesized-decorators-call-expression.ts b/tests/format/typescript/typescript-only/parenthesized-decorators-call-expression.ts deleted file mode 100644 index f5205dc73..000000000 --- a/tests/format/typescript/typescript-only/parenthesized-decorators-call-expression.ts +++ /dev/null @@ -1,2 +0,0 @@ -@(test().x("global").y()) -class X {} diff --git a/tests/format/typescript/typescript-only/parenthesized-decorators-tagged-template.ts b/tests/format/typescript/typescript-only/parenthesized-decorators-tagged-template.ts deleted file mode 100644 index ff4bca6b4..000000000 --- a/tests/format/typescript/typescript-only/parenthesized-decorators-tagged-template.ts +++ /dev/null @@ -1,4 +0,0 @@ -class Test { - @foo`bar` - text: string = "text" -}