diff --git a/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot index 9eb1f7d1401..7e24abcf6f6 100644 --- a/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration TSEnumDeclaration _error_ decorator TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures declaration TSEnumDeclaration _error_ decorator TSESTree - Error 1`] = ` +"TSError +> 1 | @decl enum Test {} + | ^^^^^ Decorators are not valid here. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot index 4851229263b..f0a67ebe105 100644 --- a/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/declaration/TSEnumDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration TSEnumDeclaration _error_ decorator Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures declaration TSEnumDeclaration _error_ decorator Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot index 502dd8aee5c..de2011df9ce 100644 --- a/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration TSInterfaceDeclaration _error_ decorator TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures declaration TSInterfaceDeclaration _error_ decorator TSESTree - Error 1`] = ` +"TSError +> 1 | @decl interface Test {} + | ^^^^^ Decorators are not valid here. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot index fb137780f45..6018ccd90e0 100644 --- a/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration TSInterfaceDeclaration _error_ decorator Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures declaration TSInterfaceDeclaration _error_ decorator Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot index 7adabe715b7..1392b9b0742 100644 --- a/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration TSTypeAliasDeclaration _error_ decorator TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures declaration TSTypeAliasDeclaration _error_ decorator TSESTree - Error 1`] = ` +"TSError +> 1 | @decl type Test = {}; + | ^^^^^ Decorators are not valid here. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot index 43ad98f601b..f99acadf19a 100644 --- a/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration TSTypeAliasDeclaration _error_ decorator Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures declaration TSTypeAliasDeclaration _error_ decorator Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot index cd619979c77..fb0803d0ca0 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration VariableDeclaration _error_ decorator TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures declaration VariableDeclaration _error_ decorator TSESTree - Error 1`] = ` +"TSError +> 1 | @decl type Test = {}; + | ^^^^^ Decorators are not valid here. + 2 |" +`; diff --git a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot index 27f74be3902..2076158e5e7 100644 --- a/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/declaration/VariableDeclaration/fixtures/_error_/decorator/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures declaration VariableDeclaration _error_ decorator Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures declaration VariableDeclaration _error_ decorator Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/1-TSESTree-Error.shot index bcb52edf68d..3055b0dc449 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-enum-declaration TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-enum-declaration TSESTree - Error 1`] = ` +"TSError + 1 | // TODO: This fixture might be too large, and if so should be split up. + 2 | +> 3 | @dec enum E {} + | ^^^^ Decorators are not valid here." +`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/3-Alignment-Error.shot index 17ba689c614..a6c9ea30e6f 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-enum-declaration Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-enum-declaration Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/1-TSESTree-Error.shot index 0d803ce647c..ab74377190c 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function TSESTree - Error 1`] = ` +"TSError + 1 | // TODO: This fixture might be too large, and if so should be split up. + 2 | +> 3 | @dec + | ^^^^ Decorators are not valid here. + 4 | function b(){} + 5 |" +`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/3-Alignment-Error.shot index 4c89abf9f72..875d107ab09 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-function Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/1-TSESTree-Error.shot index 3905750f9aa..45ea7f53044 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-interface-declaration TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-interface-declaration TSESTree - Error 1`] = ` +"TSError + 1 | // TODO: This fixture might be too large, and if so should be split up. + 2 | +> 3 | @deco() + | ^^^^^^^ Decorators are not valid here. + 4 | interface M {}" +`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/3-Alignment-Error.shot index f7a4fa57521..c8b6e5b79da 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-interface-declaration Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-interface-declaration Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/1-TSESTree-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/1-TSESTree-Error.shot index 184f3d96b4d..69123261b06 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/1-TSESTree-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/1-TSESTree-Error.shot @@ -1,3 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-variable TSESTree - Error 1`] = `"NO ERROR"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-variable TSESTree - Error 1`] = ` +"TSError + 1 | // TODO: This fixture might be too large, and if so should be split up. + 2 | +> 3 | @deco() + | ^^^^^^^ Decorators are not valid here. + 4 | const a = 1 + 5 |" +`; diff --git a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/3-Alignment-Error.shot b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/3-Alignment-Error.shot index 1c90fdcf540..a48f982c9a8 100644 --- a/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/3-Alignment-Error.shot +++ b/packages/ast-spec/src/legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/snapshots/3-Alignment-Error.shot @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-variable Error Alignment 1`] = `"Babel errored but TSESTree didn't"`; +exports[`AST Fixtures legacy-fixtures errorRecovery _error_ decorator-on-variable Error Alignment 1`] = `"Both errored"`; diff --git a/packages/ast-spec/tests/fixtures-with-differences-errors.shot b/packages/ast-spec/tests/fixtures-with-differences-errors.shot index 15692d204a1..3baa5a85efc 100644 --- a/packages/ast-spec/tests/fixtures-with-differences-errors.shot +++ b/packages/ast-spec/tests/fixtures-with-differences-errors.shot @@ -11,16 +11,12 @@ exports[`AST Fixtures List fixtures with Error differences 1`] = ` "declaration/TSDeclareFunction/fixtures/_error_/async/fixture.ts", "declaration/TSDeclareFunction/fixtures/_error_/declare-with-body/fixture.ts", "declaration/TSDeclareFunction/fixtures/_error_/missing-type-param/fixture.ts", - "declaration/TSEnumDeclaration/fixtures/_error_/decorator/fixture.ts", "declaration/TSImportEqualsDeclaration/fixtures/_error_/external-module-ref-non-string/fixture.ts", "declaration/TSImportEqualsDeclaration/fixtures/_error_/import-kind/fixture.ts", - "declaration/TSInterfaceDeclaration/fixtures/_error_/decorator/fixture.ts", "declaration/TSInterfaceDeclaration/fixtures/_error_/missing-extends/fixture.ts", "declaration/TSInterfaceDeclaration/fixtures/_error_/missing-type-param/fixture.ts", "declaration/TSInterfaceDeclaration/fixtures/_error_/non-identifier-extends/fixture.ts", - "declaration/TSTypeAliasDeclaration/fixtures/_error_/decorator/fixture.ts", "declaration/TSTypeAliasDeclaration/fixtures/_error_/missing-type-parameter/fixture.ts", - "declaration/VariableDeclaration/fixtures/_error_/decorator/fixture.ts", "element/AccessorProperty/fixtures/_error_/modifier-override-with-no-extends/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/await-without-async-function/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/class-private-identifier-field-with-accessibility-error/fixture.ts", @@ -34,10 +30,6 @@ exports[`AST Fixtures List fixtures with Error differences 1`] = ` "legacy-fixtures/basics/fixtures/_error_/import-type-error/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/new-target-in-arrow-function-body/fixture.ts", "legacy-fixtures/basics/fixtures/_error_/var-with-definite-assignment/fixture.ts", - "legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-enum-declaration/fixture.ts", - "legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-function/fixture.ts", - "legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-interface-declaration/fixture.ts", - "legacy-fixtures/errorRecovery/fixtures/_error_/decorator-on-variable/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/empty-type-arguments-in-call-expression/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/empty-type-arguments-in-new-expression/fixture.ts", "legacy-fixtures/errorRecovery/fixtures/_error_/empty-type-arguments/fixture.ts", diff --git a/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts b/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts index 081f3398ce2..d682c711fcc 100644 --- a/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts @@ -1835,7 +1835,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -1861,7 +1861,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -1882,7 +1882,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -1903,7 +1903,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -1931,7 +1931,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -1952,7 +1952,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -1973,7 +1973,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2001,7 +2001,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2022,7 +2022,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2043,7 +2043,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2071,7 +2071,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2092,7 +2092,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2113,7 +2113,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2141,7 +2141,7 @@ class DecoratedClass { public get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2162,7 +2162,7 @@ class DecoratedClass { private get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2183,7 +2183,7 @@ class DecoratedClass { protected get y() { return this.x; } - @foo @bar() set y(@foo @bar() value: x) { + @foo @bar() set z(@foo @bar() value: x) { this.x = x; } } @@ -2211,7 +2211,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() public set y(@foo @bar() value: x) { + @foo @bar() public set z(@foo @bar() value: x) { this.x = x; } } @@ -2232,7 +2232,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() private set y(@foo @bar() value: x) { + @foo @bar() private set z(@foo @bar() value: x) { this.x = x; } } @@ -2253,7 +2253,7 @@ class DecoratedClass { get y() { return this.x; } - @foo @bar() protected set y(@foo @bar() value: x) { + @foo @bar() protected set z(@foo @bar() value: x) { this.x = x; } } diff --git a/packages/eslint-plugin/tests/rules/member-ordering.test.ts b/packages/eslint-plugin/tests/rules/member-ordering.test.ts index 31eaaf86dee..9e8dda8b778 100644 --- a/packages/eslint-plugin/tests/rules/member-ordering.test.ts +++ b/packages/eslint-plugin/tests/rules/member-ordering.test.ts @@ -1455,7 +1455,7 @@ class Foo { code: ` class Foo { constructor() {} - @Dec() public A(): void; + @Dec() public A(): void {} @Dec() private B: string; private C(): void; private D: string; @@ -1474,7 +1474,7 @@ class Foo { { code: ` class Foo { - @Dec() private A(): void; + @Dec() private A(): void {} @Dec() private B: string; constructor() {} private C(): void; @@ -1511,7 +1511,7 @@ class Foo { code: ` class Foo { public A(): string; - @Dec() public B(): string; + @Dec() public B(): string {} public C(): string; d: string; diff --git a/packages/eslint-plugin/tests/rules/member-ordering/member-ordering-alphabetically-order.test.ts b/packages/eslint-plugin/tests/rules/member-ordering/member-ordering-alphabetically-order.test.ts index 1fdf812bedd..4b76427cfe8 100644 --- a/packages/eslint-plugin/tests/rules/member-ordering/member-ordering-alphabetically-order.test.ts +++ b/packages/eslint-plugin/tests/rules/member-ordering/member-ordering-alphabetically-order.test.ts @@ -1982,7 +1982,7 @@ class Foo { b2: string; public c(): void; - @Dec() d(): void; + @Dec() d(): void {} } `, options: [ diff --git a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts index 22a03ae8489..2c651a1b61d 100644 --- a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts @@ -783,8 +783,10 @@ export interface Event { }, // https://github.com/typescript-eslint/typescript-eslint/issues/2369 ` -export default function (@Optional() value = []) { - return value; +export class Test { + constructor(@Optional() value: number[] = []) { + console.log(value); + } } function Optional() { diff --git a/packages/scope-manager/tests/eslint-scope/references.test.ts b/packages/scope-manager/tests/eslint-scope/references.test.ts index 15ed88c9a1e..0b49cab0f7f 100644 --- a/packages/scope-manager/tests/eslint-scope/references.test.ts +++ b/packages/scope-manager/tests/eslint-scope/references.test.ts @@ -582,7 +582,7 @@ describe('References:', () => { declare class C { @deco - foo(): TypeC; + foo(): TypeC {}; } `, { diff --git a/packages/scope-manager/tests/fixtures/decorators/accessor.ts b/packages/scope-manager/tests/fixtures/decorators/accessor.ts index 764ea5e3340..abe0263ac3f 100644 --- a/packages/scope-manager/tests/fixtures/decorators/accessor.ts +++ b/packages/scope-manager/tests/fixtures/decorators/accessor.ts @@ -5,5 +5,5 @@ class Foo { return 1; } @decorator - set foo() {} + set bar(value) {} } diff --git a/packages/scope-manager/tests/fixtures/decorators/accessor.ts.shot b/packages/scope-manager/tests/fixtures/decorators/accessor.ts.shot index 7cdbee72d9f..9d315fef25c 100644 --- a/packages/scope-manager/tests/fixtures/decorators/accessor.ts.shot +++ b/packages/scope-manager/tests/fixtures/decorators/accessor.ts.shot @@ -78,10 +78,22 @@ ScopeManager { isValueVariable: true, isTypeVariable: true, }, + Variable$8 { + defs: [ + ParameterDefinition$4 { + name: Identifier<"value">, + node: FunctionExpression$3, + }, + ], + name: "value", + references: [], + isValueVariable: true, + isTypeVariable: false, + }, ], scopes: [ GlobalScope$1 { - block: Program$3, + block: Program$4, isStrict: false, references: [], set: Map { @@ -127,7 +139,7 @@ ScopeManager { ], }, FunctionScope$4 { - block: FunctionExpression$4, + block: FunctionExpression$5, isStrict: true, references: [], set: Map { @@ -140,16 +152,18 @@ ScopeManager { ], }, FunctionScope$5 { - block: FunctionExpression$5, + block: FunctionExpression$3, isStrict: true, references: [], set: Map { "arguments" => Variable$7, + "value" => Variable$8, }, type: "function", upper: ClassScope$3, variables: [ Variable$7, + Variable$8, ], }, ], diff --git a/packages/scope-manager/tests/fixtures/decorators/parameter.ts b/packages/scope-manager/tests/fixtures/decorators/parameter.ts index 2b9b32b2bb2..a518ad975a0 100644 --- a/packages/scope-manager/tests/fixtures/decorators/parameter.ts +++ b/packages/scope-manager/tests/fixtures/decorators/parameter.ts @@ -1,7 +1,4 @@ function decorator() {} -function foo( - @decorator a, - @decorator [b], - @decorator { c }, - @decorator d = 1, -) {} +class A { + foo(@decorator a, @decorator [b], @decorator { c }, @decorator d = 1) {} +} diff --git a/packages/scope-manager/tests/fixtures/decorators/parameter.ts.shot b/packages/scope-manager/tests/fixtures/decorators/parameter.ts.shot index 07744f723ab..491ddab990e 100644 --- a/packages/scope-manager/tests/fixtures/decorators/parameter.ts.shot +++ b/packages/scope-manager/tests/fixtures/decorators/parameter.ts.shot @@ -58,28 +58,40 @@ ScopeManager { }, Variable$4 { defs: [ - FunctionNameDefinition$2 { - name: Identifier<"foo">, - node: FunctionDeclaration$2, + ClassNameDefinition$2 { + name: Identifier<"A">, + node: ClassDeclaration$2, }, ], - name: "foo", + name: "A", references: [], isValueVariable: true, - isTypeVariable: false, + isTypeVariable: true, }, Variable$5 { + defs: [ + ClassNameDefinition$3 { + name: Identifier<"A">, + node: ClassDeclaration$2, + }, + ], + name: "A", + references: [], + isValueVariable: true, + isTypeVariable: true, + }, + Variable$6 { defs: [], name: "arguments", references: [], isValueVariable: true, isTypeVariable: true, }, - Variable$6 { + Variable$7 { defs: [ - ParameterDefinition$3 { + ParameterDefinition$4 { name: Identifier<"a">, - node: FunctionDeclaration$2, + node: FunctionExpression$3, }, ], name: "a", @@ -87,11 +99,11 @@ ScopeManager { isValueVariable: true, isTypeVariable: false, }, - Variable$7 { + Variable$8 { defs: [ - ParameterDefinition$4 { + ParameterDefinition$5 { name: Identifier<"b">, - node: FunctionDeclaration$2, + node: FunctionExpression$3, }, ], name: "b", @@ -99,11 +111,11 @@ ScopeManager { isValueVariable: true, isTypeVariable: false, }, - Variable$8 { + Variable$9 { defs: [ - ParameterDefinition$5 { + ParameterDefinition$6 { name: Identifier<"c">, - node: FunctionDeclaration$2, + node: FunctionExpression$3, }, ], name: "c", @@ -111,11 +123,11 @@ ScopeManager { isValueVariable: true, isTypeVariable: false, }, - Variable$9 { + Variable$10 { defs: [ - ParameterDefinition$6 { + ParameterDefinition$7 { name: Identifier<"d">, - node: FunctionDeclaration$2, + node: FunctionExpression$3, }, ], name: "d", @@ -127,8 +139,8 @@ ScopeManager { isTypeReference: false, isValueReference: true, isWrite: true, - resolved: Variable$9, - writeExpr: Literal$3, + resolved: Variable$10, + writeExpr: Literal$4, }, ], isValueVariable: true, @@ -137,13 +149,13 @@ ScopeManager { ], scopes: [ GlobalScope$1 { - block: Program$4, + block: Program$5, isStrict: false, references: [], set: Map { "const" => ImplicitGlobalConstTypeVariable, "decorator" => Variable$2, - "foo" => Variable$4, + "A" => Variable$4, }, type: "global", upper: null, @@ -166,9 +178,22 @@ ScopeManager { Variable$3, ], }, - FunctionScope$3 { - block: FunctionDeclaration$2, - isStrict: false, + ClassScope$3 { + block: ClassDeclaration$2, + isStrict: true, + references: [], + set: Map { + "A" => Variable$5, + }, + type: "class", + upper: GlobalScope$1, + variables: [ + Variable$5, + ], + }, + FunctionScope$4 { + block: FunctionExpression$3, + isStrict: true, references: [ Reference$1, Reference$2, @@ -177,20 +202,20 @@ ScopeManager { Reference$5, ], set: Map { - "arguments" => Variable$5, - "a" => Variable$6, - "b" => Variable$7, - "c" => Variable$8, - "d" => Variable$9, + "arguments" => Variable$6, + "a" => Variable$7, + "b" => Variable$8, + "c" => Variable$9, + "d" => Variable$10, }, type: "function", - upper: GlobalScope$1, + upper: ClassScope$3, variables: [ - Variable$5, Variable$6, Variable$7, Variable$8, Variable$9, + Variable$10, ], }, ], diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 62e27929d8d..0a10359d41d 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -25,6 +25,7 @@ import { isESTreeClassMember, isOptional, isThisInTypeQuery, + nodeCanBeDecorated, nodeHasIllegalDecorators, nodeIsPresent, unescapeStringLiteralText, @@ -3118,6 +3119,7 @@ export class Converter { return; } + // typescript<5.0.0 if (nodeHasIllegalDecorators(node)) { this.#throwError( node.illegalDecorators[0], @@ -3125,7 +3127,27 @@ export class Converter { ); } - for (const modifier of getModifiers(node) ?? []) { + for (const decorator of getDecorators( + node, + /* includeIllegalDecorators */ true, + ) ?? []) { + // `checkGrammarModifiers` function in typescript + if (!nodeCanBeDecorated(node as TSNode)) { + if (ts.isMethodDeclaration(node) && !nodeIsPresent(node.body)) { + this.#throwError( + decorator, + 'A decorator can only decorate a method implementation, not an overload.', + ); + } else { + this.#throwError(decorator, 'Decorators are not valid here.'); + } + } + } + + for (const modifier of getModifiers( + node, + /* includeIllegalModifiers */ true, + ) ?? []) { if (modifier.kind !== SyntaxKind.ReadonlyKeyword) { if ( node.kind === SyntaxKind.PropertySignature || diff --git a/packages/typescript-estree/src/getModifiers.ts b/packages/typescript-estree/src/getModifiers.ts index 24ef670a2c0..00f1011aa4b 100644 --- a/packages/typescript-estree/src/getModifiers.ts +++ b/packages/typescript-estree/src/getModifiers.ts @@ -6,6 +6,7 @@ const isAtLeast48 = typescriptVersionIsAtLeast['4.8']; export function getModifiers( node: ts.Node | null | undefined, + includeIllegalModifiers = false, ): undefined | ts.Modifier[] { if (node == null) { return undefined; @@ -13,9 +14,9 @@ export function getModifiers( if (isAtLeast48) { // eslint-disable-next-line deprecation/deprecation -- this is safe as it's guarded - if (ts.canHaveModifiers(node)) { + if (includeIllegalModifiers || ts.canHaveModifiers(node)) { // eslint-disable-next-line deprecation/deprecation -- this is safe as it's guarded - const modifiers = ts.getModifiers(node); + const modifiers = ts.getModifiers(node as ts.HasModifiers); return modifiers ? Array.from(modifiers) : undefined; } @@ -32,6 +33,7 @@ export function getModifiers( export function getDecorators( node: ts.Node | null | undefined, + includeIllegalDecorators = false, ): undefined | ts.Decorator[] { if (node == null) { return undefined; @@ -39,9 +41,9 @@ export function getDecorators( if (isAtLeast48) { // eslint-disable-next-line deprecation/deprecation -- this is safe as it's guarded - if (ts.canHaveDecorators(node)) { + if (includeIllegalDecorators || ts.canHaveDecorators(node)) { // eslint-disable-next-line deprecation/deprecation -- this is safe as it's guarded - const decorators = ts.getDecorators(node); + const decorators = ts.getDecorators(node as ts.HasDecorators); return decorators ? Array.from(decorators) : undefined; } diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 738b673a3d9..da802c8d5cc 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -2,7 +2,7 @@ import * as ts from 'typescript'; import { getModifiers } from './getModifiers'; import { xhtmlEntities } from './jsx/xhtml-entities'; -import type { TSESTree } from './ts-estree'; +import type { TSESTree, TSNode } from './ts-estree'; import { AST_NODE_TYPES, AST_TOKEN_TYPES } from './ts-estree'; import { typescriptVersionIsAtLeast } from './version-check'; @@ -764,3 +764,86 @@ export function getContainingFunction( ): ts.SignatureDeclaration | undefined { return ts.findAncestor(node.parent, ts.isFunctionLike); } + +// `ts.hasAbstractModifier` +function hasAbstractModifier(node: ts.Node): boolean { + return hasModifier(SyntaxKind.AbstractKeyword, node); +} + +// `ts.getThisParameter` +function getThisParameter( + signature: ts.SignatureDeclaration, +): ts.ParameterDeclaration | null { + if (signature.parameters.length && !ts.isJSDocSignature(signature)) { + const thisParameter = signature.parameters[0]; + if (parameterIsThisKeyword(thisParameter)) { + return thisParameter; + } + } + + return null; +} + +// `ts.parameterIsThisKeyword` +function parameterIsThisKeyword(parameter: ts.ParameterDeclaration): boolean { + return isThisIdentifier(parameter.name); +} + +// Rewrite version of `ts.nodeCanBeDecorated` +// Returns `true` for both `useLegacyDecorators: true` and `useLegacyDecorators: false` +export function nodeCanBeDecorated(node: TSNode): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + return true; + case SyntaxKind.ClassExpression: + // `ts.nodeCanBeDecorated` returns `false` if `useLegacyDecorators: true` + return true; + case SyntaxKind.PropertyDeclaration: { + const { parent } = node; + + // `ts.nodeCanBeDecorated` uses this if `useLegacyDecorators: true` + if (ts.isClassDeclaration(parent)) { + return true; + } + + // `ts.nodeCanBeDecorated` uses this if `useLegacyDecorators: false` + if (ts.isClassLike(parent) && !hasAbstractModifier(node)) { + return true; + } + + return false; + } + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: { + const { parent } = node; + // In `ts.nodeCanBeDecorated` + // when `useLegacyDecorators: true` uses `ts.isClassDeclaration` + // when `useLegacyDecorators: true` uses `ts.isClassLike` + return ( + Boolean(node.body) && + (ts.isClassDeclaration(parent) || ts.isClassLike(parent)) + ); + } + case SyntaxKind.Parameter: { + // `ts.nodeCanBeDecorated` returns `false` if `useLegacyDecorators: false` + + const { parent } = node; + const grandparent = parent.parent; + + return ( + Boolean(parent) && + 'body' in parent && + Boolean(parent.body) && + (parent.kind === SyntaxKind.Constructor || + parent.kind === SyntaxKind.MethodDeclaration || + parent.kind === SyntaxKind.SetAccessor) && + getThisParameter(parent) !== node && + Boolean(grandparent) && + grandparent.kind === SyntaxKind.ClassDeclaration + ); + } + } + + return false; +}