Skip to content

Commit ad0f2be

Browse files
gavinbarronbradzacher
authored andcommitted
fix(eslint-plugin): member-naming false flagging constructors (#376)
Fixes #359
1 parent bea6b92 commit ad0f2be

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

packages/eslint-plugin/docs/rules/member-naming.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ It can be helpful to enforce naming conventions for `private` (and sometimes `pr
44

55
## Rule Details
66

7-
This rule allows you to enforce conventions for class property names by their visibility. By default, it enforces nothing.
7+
This rule allows you to enforce conventions for class property and method names by their visibility. By default, it enforces nothing.
8+
9+
> Note: constructors are explicitly ignored regardless of the the regular expression options provided
810
911
## Options
1012

packages/eslint-plugin/src/rules/member-naming.ts

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export default util.createRule<Options, MessageIds>({
7575
const accessibility: Modifiers = node.accessibility || 'public';
7676
const convention = conventions[accessibility];
7777

78+
const method = node as TSESTree.MethodDefinition;
79+
if (method.kind === 'constructor') return;
80+
7881
if (!convention || convention.test(name)) return;
7982

8083
context.report({

packages/eslint-plugin/tests/rules/member-naming.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ ruleTester.run('member-naming', rule, {
1111
code: `class Class { _fooBar() {} }`,
1212
options: [{ public: '^_' }],
1313
},
14+
{
15+
code: `class Class { private constructor(); _fooBar() {} }`,
16+
options: [{ private: '^_' }],
17+
},
18+
{
19+
code: `class Class { constructor() {}; _fooBar() {} }`,
20+
options: [{ public: '^_' }],
21+
},
1422
{
1523
code: `class Class { public _fooBar() {} }`,
1624
options: [{ public: '^_' }],

0 commit comments

Comments
 (0)