Skip to content

Commit

Permalink
fix(eslint-plugin): crash in no-dupe-class-members (v5) (#3813)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored and bradzacher committed Sep 21, 2021
1 parent 41e7338 commit 7b79856
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/eslint-plugin/src/rules/no-dupe-class-members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ export default util.createRule<Options, MessageIds>({
create(context) {
const rules = baseRule.create(context);

function wrapMemberDefinitionListener(
coreListener: (node: TSESTree.MethodDefinition) => void,
): (node: TSESTree.MethodDefinition) => void {
return (node: TSESTree.MethodDefinition): void => {
function wrapMemberDefinitionListener<
N extends TSESTree.MethodDefinition | TSESTree.PropertyDefinition,
>(coreListener: (node: N) => void): (node: N) => void {
return (node: N): void => {
if (node.computed) {
return;
}

if (node.value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
if (
node.value &&
node.value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression
) {
return;
}

Expand Down
22 changes: 22 additions & 0 deletions packages/eslint-plugin/tests/rules/no-dupe-class-members.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ class A {
class A {
set foo(value) {}
foo() {}
}
`,
errors: [
{ line: 4, column: 3, messageId: 'unexpected', data: { name: 'foo' } },
],
},
{
code: `
class A {
foo;
foo = 42;
}
`,
errors: [
{ line: 4, column: 3, messageId: 'unexpected', data: { name: 'foo' } },
],
},
{
code: `
class A {
foo;
foo() {}
}
`,
errors: [
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/typings/eslint-rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ declare module 'eslint/lib/rules/no-dupe-class-members' {
MethodDefinition?: (node: TSESTree.MethodDefinition) => void;
// for ESLint v8
'MethodDefinition, PropertyDefinition'?: (
node: TSESTree.MethodDefinition /* | TSESTree.PropertyDefinition */,
node: TSESTree.MethodDefinition | TSESTree.PropertyDefinition,
) => void;
}
>;
Expand Down Expand Up @@ -646,7 +646,7 @@ declare module 'eslint/lib/rules/no-extra-semi' {
MethodDefinition?: (node: TSESTree.MethodDefinition) => void;
// for ESLint v8
'MethodDefinition, PropertyDefinition'?: (
node: TSESTree.MethodDefinition /* | TSESTree.PropertyDefinition */,
node: TSESTree.MethodDefinition | TSESTree.PropertyDefinition,
) => void;
}
>;
Expand Down

0 comments on commit 7b79856

Please sign in to comment.