Skip to content

Commit 4b09644

Browse files
ota-meshibradzacher
authored andcommitted
fix(eslint-plugin): crash in no-dupe-class-members (v5) (#3813)
1 parent 0eefe5e commit 4b09644

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

Diff for: packages/eslint-plugin/src/rules/no-dupe-class-members.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ export default util.createRule<Options, MessageIds>({
2727
create(context) {
2828
const rules = baseRule.create(context);
2929

30-
function wrapMemberDefinitionListener(
31-
coreListener: (node: TSESTree.MethodDefinition) => void,
32-
): (node: TSESTree.MethodDefinition) => void {
33-
return (node: TSESTree.MethodDefinition): void => {
30+
function wrapMemberDefinitionListener<
31+
N extends TSESTree.MethodDefinition | TSESTree.PropertyDefinition,
32+
>(coreListener: (node: N) => void): (node: N) => void {
33+
return (node: N): void => {
3434
if (node.computed) {
3535
return;
3636
}
3737

38-
if (node.value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
38+
if (
39+
node.value &&
40+
node.value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression
41+
) {
3942
return;
4043
}
4144

Diff for: packages/eslint-plugin/tests/rules/no-dupe-class-members.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ class A {
166166
class A {
167167
set foo(value) {}
168168
foo() {}
169+
}
170+
`,
171+
errors: [
172+
{ line: 4, column: 3, messageId: 'unexpected', data: { name: 'foo' } },
173+
],
174+
},
175+
{
176+
code: `
177+
class A {
178+
foo;
179+
foo = 42;
180+
}
181+
`,
182+
errors: [
183+
{ line: 4, column: 3, messageId: 'unexpected', data: { name: 'foo' } },
184+
],
185+
},
186+
{
187+
code: `
188+
class A {
189+
foo;
190+
foo() {}
169191
}
170192
`,
171193
errors: [

Diff for: packages/eslint-plugin/typings/eslint-rules.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ declare module 'eslint/lib/rules/no-dupe-class-members' {
234234
MethodDefinition?: (node: TSESTree.MethodDefinition) => void;
235235
// for ESLint v8
236236
'MethodDefinition, PropertyDefinition'?: (
237-
node: TSESTree.MethodDefinition /* | TSESTree.PropertyDefinition */,
237+
node: TSESTree.MethodDefinition | TSESTree.PropertyDefinition,
238238
) => void;
239239
}
240240
>;
@@ -646,7 +646,7 @@ declare module 'eslint/lib/rules/no-extra-semi' {
646646
MethodDefinition?: (node: TSESTree.MethodDefinition) => void;
647647
// for ESLint v8
648648
'MethodDefinition, PropertyDefinition'?: (
649-
node: TSESTree.MethodDefinition /* | TSESTree.PropertyDefinition */,
649+
node: TSESTree.MethodDefinition | TSESTree.PropertyDefinition,
650650
) => void;
651651
}
652652
>;

0 commit comments

Comments
 (0)