Skip to content

fix(eslint-plugin): member-naming #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/eslint-plugin/docs/rules/member-naming.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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