Navigation Menu

Skip to content

Commit

Permalink
fix(eslint-plugin): member-naming false flagging constructors (#376)
Browse files Browse the repository at this point in the history
Fixes #359
  • Loading branch information
gavinbarron authored and bradzacher committed Mar 27, 2019
1 parent bea6b92 commit ad0f2be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/eslint-plugin/docs/rules/member-naming.md
Expand Up @@ -4,7 +4,9 @@ It can be helpful to enforce naming conventions for `private` (and sometimes `pr

## Rule Details

This rule allows you to enforce conventions for class property names by their visibility. By default, it enforces nothing.
This rule allows you to enforce conventions for class property and method names by their visibility. By default, it enforces nothing.

> Note: constructors are explicitly ignored regardless of the the regular expression options provided
## Options

Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-plugin/src/rules/member-naming.ts
Expand Up @@ -75,6 +75,9 @@ export default util.createRule<Options, MessageIds>({
const accessibility: Modifiers = node.accessibility || 'public';
const convention = conventions[accessibility];

const method = node as TSESTree.MethodDefinition;
if (method.kind === 'constructor') return;

if (!convention || convention.test(name)) return;

context.report({
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin/tests/rules/member-naming.test.ts
Expand Up @@ -11,6 +11,14 @@ ruleTester.run('member-naming', rule, {
code: `class Class { _fooBar() {} }`,
options: [{ public: '^_' }],
},
{
code: `class Class { private constructor(); _fooBar() {} }`,
options: [{ private: '^_' }],
},
{
code: `class Class { constructor() {}; _fooBar() {} }`,
options: [{ public: '^_' }],
},
{
code: `class Class { public _fooBar() {} }`,
options: [{ public: '^_' }],
Expand Down

0 comments on commit ad0f2be

Please sign in to comment.