Skip to content

Commit

Permalink
fix(eslint-plugin): [no-extran-class] allowWithDecorator should ignor…
Browse files Browse the repository at this point in the history
…e other errors (#3160)
  • Loading branch information
a-tarasyuk committed Mar 15, 2021
1 parent d9e7916 commit a148673
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-extraneous-class.ts
Expand Up @@ -79,13 +79,13 @@ export default util.createRule<Options, MessageIds>({
| 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;
}

Expand Down
31 changes: 31 additions & 0 deletions packages/eslint-plugin/tests/rules/no-extraneous-class.test.ts
Expand Up @@ -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: [
Expand Down Expand Up @@ -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',
},
],
},
],
});

0 comments on commit a148673

Please sign in to comment.