Skip to content

Commit

Permalink
fix(eslint-plugin): [class-methods-use-this] detect a problematic cas…
Browse files Browse the repository at this point in the history
…e for private/protected members if `ignoreClassesThatImplementAnInterface` is `true`
  • Loading branch information
tetsuharuohzeki committed Sep 30, 2023
1 parent 0545fc6 commit 4d4e714
Show file tree
Hide file tree
Showing 2 changed files with 441 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/eslint-plugin/src/rules/class-methods-use-this.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ export default util.createRule<Options, MessageIds>({
return oldStack;
}

function isPublicMethod(
accessibility: TSESTree.Accessibility | undefined,
): boolean {
if (!accessibility || accessibility === 'public') {
return true;
}

return false;
}

/**
* Check if the node is an instance method not excluded by config
*/
Expand Down Expand Up @@ -185,7 +195,8 @@ export default util.createRule<Options, MessageIds>({
stackContext.usesThis ||
(ignoreOverrideMethods && stackContext.member.override) ||
(ignoreClassesThatImplementAnInterface &&
stackContext.class.implements != null)
stackContext.class.implements != null &&
isPublicMethod(stackContext.member.accessibility))
) {
return;
}
Expand Down

0 comments on commit 4d4e714

Please sign in to comment.