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
Rule proposal: no-unused-private-class-members #4571
Comments
#private members are completely safe to mark as unused because they are 100%, runtime enforced to be only accessible within the class they are defined. However Which means we cannot statically detect the valid usages across module boundaries. This is generally I would recommend using #private instead of |
Actually, TypeScript is already complaining about private members not being used. I could enable the |
Yes, but I don't know if the compiler option actually detects the indexed access across files. |
Actually the compiler detects indexed access, but not across files. See Which is fine for me because I don't ever want to access private members outside of a class. The problem is that inside the same file it doesn't complain. Not that big of a deal though, since even without an eslint rule for it, I haven't seen anyone using indexed access - and it would much easier to spot during code review than unused code. It would be nice to get |
our
An autofixer would not be possible for this because it wouldn't be able to fix cross-module access! In general we don't like writing rules that just ban a feature unless we can add real value with a standalone rule. |
@bradzacher Thanks for the detailed reply here. How do you think we can get a fixer in to ban and autofix the ---- EDIT ---- I reread and noticed you already said a fixer is not possible. Ignore me! |
Also, unit tests relying on any private methods would also start failing if they weren't treated as block boxes. Wow, much harder problem than I thought! |
Using
|
This comment was marked as off-topic.
This comment was marked as off-topic.
@PhilippeMorier please see our contributing guide's section on issue comments: https://typescript-eslint.io/contributing/issues#commenting. We ask that folks don't post "is there an update?" messages on issues. They don't add to the discussion. If nothing is visible on GitHub, then nothing has happened. Zamiell is waiting for our re-review on some other PRs (sorry for the delay 😅) as it is. |
Description
To complement the original
no-unused-private-class-members
rule which works with typescript but doesn't detect theprivate
keyword:— From: https://eslint.org/docs/rules/no-unused-private-class-members#no-unused-private-class-members
See also: eslint/eslint#14859.
Fail
Pass
The text was updated successfully, but these errors were encountered: