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 Oct 18, 2023
1 parent 556cfc8 commit d4b5aaf
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 @@ -145,6 +145,16 @@ export default 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 @@ -190,7 +200,8 @@ export default 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 d4b5aaf

Please sign in to comment.