Skip to content

Commit

Permalink
feat: add support of "exceptMethods"
Browse files Browse the repository at this point in the history
  • Loading branch information
lonyele committed Sep 6, 2019
1 parent 6a5c77c commit 8f44968
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/eslint-plugin/src/rules/explicit-member-accessibility.ts
Expand Up @@ -18,6 +18,7 @@ interface Config {
properties?: AccessibilityLevel;
parameterProperties?: AccessibilityLevel;
};
exceptMethods?: string[];
}

type Options = [Config];
Expand Down Expand Up @@ -57,8 +58,15 @@ export default util.createRule<Options, MessageIds>({
properties: accessibilityLevel,
parameterProperties: accessibilityLevel,
},

additionalProperties: false,
},
exceptMethods: {
type: 'array',
items: {
type: 'string',
},
},
},
additionalProperties: false,
},
Expand All @@ -74,7 +82,7 @@ export default util.createRule<Options, MessageIds>({
const methodCheck = overrides.methods || baseCheck;
const propCheck = overrides.properties || baseCheck;
const paramPropCheck = overrides.parameterProperties || baseCheck;

const exceptMethods = option.exceptMethods || [];
/**
* Generates the report for rule violations
*/
Expand Down Expand Up @@ -116,14 +124,16 @@ export default util.createRule<Options, MessageIds>({
nodeType = `${methodDefinition.kind} property accessor`;
break;
}
if (check === 'off') {
return;
}

const methodName = util.getNameFromClassMember(
methodDefinition,
sourceCode,
);

if (check === 'off' || exceptMethods.includes(methodName)) {
return;
}

if (
check === 'no-public' &&
methodDefinition.accessibility === 'public'
Expand Down
Expand Up @@ -258,6 +258,21 @@ class Test {
},
],
},
{
filename: 'test.ts',
code: `
class Test {
getX () {
return this.x
}
}
`,
options: [
{
exceptMethods: ['getX'],
},
],
},
],
invalid: [
{
Expand Down

0 comments on commit 8f44968

Please sign in to comment.