diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index 996dd0ea71c..e57ee5546a3 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -79,13 +79,13 @@ export default util.createRule({ | TSESTree.ClassExpression | undefined; - if (!parent || parent.superClass) { + if (!parent || parent.superClass || isAllowWithDecorator(parent)) { return; } const reportNode = 'id' in parent && parent.id ? parent.id : parent; if (node.body.length === 0) { - if (allowEmpty || isAllowWithDecorator(parent)) { + if (allowEmpty) { return; } diff --git a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts index 2bb96f196ef..44d32490a10 100644 --- a/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts +++ b/packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts @@ -76,6 +76,19 @@ class Foo {} `, options: [{ allowWithDecorator: true }], }, + { + code: ` +@FooDecorator +class Foo { + constructor(foo: Foo) { + foo.subscribe(a => { + console.log(a); + }); + } +} + `, + options: [{ allowWithDecorator: true }], + }, ], invalid: [ @@ -150,5 +163,23 @@ class Foo {} }, ], }, + { + code: ` +@FooDecorator +class Foo { + constructor(foo: Foo) { + foo.subscribe(a => { + console.log(a); + }); + } +} + `, + options: [{ allowWithDecorator: false }], + errors: [ + { + messageId: 'onlyConstructor', + }, + ], + }, ], });