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
Detect unused private members in classes #14859
Comments
I don't think we want to update I could see the utility of a new rule, |
Yes a new rule would be absolutely fine by me. Would you be okay if I submit a PR with that? |
I will champion this as a new rule. We still need to get feedback from the team so please hold off on a PR until we mark this as accepted. |
Makes sense to add this rule. If we want to include private methods in the same rule (I don't see a reason why we shouldn't), a name like |
Makes sense to add this rule 👍 |
Makes sense to me. |
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.
I know this issue hasn't been marked as accepted yet. However, given the positive response thus far and me having a Friday to work on open source contributions, I figured I can implement the rule relatively straightforwardly (#14895). If this rule ends up not being accepted, I am planning to copy it into our DevTools rules anyways. So the work won't be thrown away for me personally. P.S. What are the odds that this issue has number 14859 and the PR I made number 14895. Made me chuckle 😄 |
I'm reasonably certain this will be accepted, it just takes time to get in front of more of the team. |
@eslint/eslint-tsc still looking for approval here |
I included this rule in DevTools today and it found a whole bunch of unused fields 🎉 https://crrev.com/c/3310610 I didn't encounter any further issues nor false positives, so I think we are good here 😄 |
What rule do you want to change?
no-unused-vars
(arguably this could be a separate rule as well, something likeno-unused-private-fields
)Does this change cause the rule to produce more or fewer warnings?
More
How will the change be implemented? (New option, new default behavior, etc.)?
New default behavior
Please provide some example code that this change will affect:
What does the rule currently do for this code?
Nothing
What will the rule do after it's changed?
Report unused fields declared in a class. In the above example, it should report that both
#unusedField
and#usedFieldOnlyInWrite
are unused. This should be possible, as private fields are only concerned in a particular class context, so you can collect all fields in a class, iterate through all usages and mark does that are never read as unused.Are you willing to submit a pull request to implement this change?
I would be able to give it a go, but I am not sure how difficult this would be.
The text was updated successfully, but these errors were encountered: