-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
New: Add no-unused-private-class-members rule (fixes #14859) #14895
New: Add no-unused-private-class-members rule (fixes #14859) #14895
Conversation
For any private class property or method, report those that are unused. Since private class members can only be accessed in the same class body, we can safely assume that all usages are processed when we leave the ClassBody scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. We just can’t add to recommended stuff this point.
Note to team: this is covered by the old CLA |
Thanks @mdjermanovic for your detailed review! I should have some time this week to fix these issues. |
Also remove the rule from recommended for now, as that is a breaking change.
|
It's Friday and that means edge case galore! I think I handled all cases now, with loads of new tests 😄 |
This also removes the usage of optional chaining, which isn't supported yet on Node environments that ESLint supports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. left some notes where I thought we could improve readability by shortening up some of the names.
@nzakas Done 👍 |
@mdjermanovic Thanks for all the edge cases! I battle-hardened the nested classes scenarios and also added another regression test with regards to double usage of an inner class property, where it would incorrectly mark the parent class property as used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
I am on GitHub right now, so I hope that my GitHub edit was working. The last change I can make tomorrow (I think) on my laptop. |
Ah nvm. I will just clean it up tomorrow so that I can fix the linter as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for contributing!
For any private class property or method, report those that are
unused. Since private class members can only be accessed in the
same class body, we can safely assume that all usages are processed
when we leave the ClassBody scope.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[X] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Implement the rule for reporting unused private class members (#14859)
Is there anything you'd like reviewers to focus on?
I have tried to figure out all potential edge cases for usages of these variables. There might be edge cases that I missed, so it would be great to add more if you can think of any.