no-unused-private-class-members
Private class members that are declared but never used are likely an error due to incomplete refactoring. They take up space and can confuse readers.Rule Type: Problem
Fixable: No
Fixable: No
Rule Details
This rule reports unused private class members:- Private fields/methods: Unused if their value is never read
- Private accessors: Unused if never accessed (read or written)
Examples
Incorrect Code
Correct Code
Understanding “Used”
Fields and Methods Must Be Read
Accessors Must Be Accessed
Common Patterns
Leftover from Refactoring
Write-Only Fields
Self-Updating Fields
Why Private Members?
Private members are often unused because:- Incomplete implementation - You planned to use it but didn’t
- Refactoring artifact - Used to be needed, no longer is
- Dead code - Experimental code that never got used
Refactoring Tips
Remove or Make Public
Add Missing Usage
When Not to Use It
You might disable this rule if:- You’re in the middle of development and have placeholder private members
- You want to keep private members for documentation purposes
Comparison with no-unused-vars
no-unused-vars- checks variables, parameters, importsno-unused-private-class-members- checks private class members specifically