Skip to content
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

Merged
merged 12 commits into from Oct 22, 2021

Conversation

TimvdLippe
Copy link
Contributor

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.

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.
@eslint-github-bot eslint-github-bot bot added the triage An ESLint team member will look at this issue soon label Aug 6, 2021
@mdjermanovic mdjermanovic added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 6, 2021
@btmills btmills added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Aug 26, 2021
Copy link
Member

@nzakas nzakas left a 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.

conf/eslint-recommended.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
@nzakas
Copy link
Member

nzakas commented Sep 16, 2021

Note to team: this is covered by the old CLA

@TimvdLippe
Copy link
Contributor Author

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.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 1, 2021

CLA Not Signed

  • - Tim van der Lippe The commit (8b2d49f ,4c9f57a7e4e4301d6f46d98edc1256f7a7043bea ,d253c4e52fcb0ca917eead9bc17c19fa1c5df3bb ,185367576a2ac78bbc193f6422306d96cb5b25b8 ,71d7a9b51267e90ad5af43ef374726ff9bb5526c ,72e11020fd61a7393054c96f4178cfd69d48656b ,6dd74040b848ce77cd695d74758c6c08a7bc56ab ,855484b71b287acbc8e6638354aeab59547f5bab ,5b6b934a2bc6111b0be7ef6a3cd369c2e7c7733e ,273cbf6739d81066ce8cad27b2a662b46ffb3b41 ,73dbc7fd35878d05238a3108075200b5a5663759 ,5433a355538aef766e204762266a8ab04cdb9f92) is not authorized under a signed CLA. Please click here to be authorized. For further assistance with EasyCLA, please submit a support request ticket.

@TimvdLippe
Copy link
Contributor Author

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.
Copy link
Member

@nzakas nzakas left a 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.

lib/rules/no-unused-private-class-members.js Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
@TimvdLippe
Copy link
Contributor Author

@nzakas Done 👍

lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
@TimvdLippe
Copy link
Contributor Author

@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.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

lib/rules/no-unused-private-class-members.js Show resolved Hide resolved
docs/rules/no-unused-private-class-members.md Outdated Show resolved Hide resolved
docs/rules/no-unused-private-class-members.md Show resolved Hide resolved
docs/rules/no-unused-private-class-members.md Show resolved Hide resolved
docs/rules/no-unused-private-class-members.md Show resolved Hide resolved
docs/rules/no-unused-private-class-members.md Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Show resolved Hide resolved
lib/rules/no-unused-private-class-members.js Outdated Show resolved Hide resolved
TimvdLippe and others added 3 commits October 14, 2021 20:57
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@TimvdLippe
Copy link
Contributor Author

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.

@TimvdLippe
Copy link
Contributor Author

Ah nvm. I will just clean it up tomorrow so that I can fix the linter as well.

@mdjermanovic mdjermanovic changed the title New: Report unused private class members (fixes #14859) New: Add no-unused-private-class-members rule (fixes #14859) Oct 22, 2021
Copy link
Member

@mdjermanovic mdjermanovic left a 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!

@mdjermanovic mdjermanovic merged commit 3d370fb into eslint:main Oct 22, 2021
@TimvdLippe TimvdLippe deleted the no-unused-private-class-members branch October 22, 2021 13:48
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 21, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants