Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Description
To complement the originalno-unused-private-class-members rule which works with typescript but doesn't detect theprivate keyword:
Private class members that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such class members take up space in the code and can lead to confusion by readers.
— From:https://eslint.org/docs/rules/no-unused-private-class-members#no-unused-private-class-members
See also:eslint/eslint#14859.
Fail
classFoo{ #unusedMember:number;privateanotherUnusedMember:number;}classFoo{ #usedOnlyInWrite:number;constructor(privateanotherUsedOnlyInWrite:number){// noop}method(){this.#usedOnlyInWrite=42;}}classFoo{ #usedOnlyToUpdateItself=5;method(){this.#usedOnlyToUpdateItself++;}}classFoo{ #unusedMethod(){}privateanotherUnusedMethod(){}}classFoo{get #unusedAccessor(){}set #unusedAccessor(value){}privategetanotherUnusedAccessor(){}privatesetanotherUnusedAccessor(value){}}
Pass
classFoo{ #usedMember=35;privateanotherUsedMember=7;method(){returnthis.#usedMember+this.anotherUsedMember;}}classFoo{constructor(privatereadonlyusedMember:number){// noop}doSomething(){returnthis.usedMember/42;}}classFoo{ #usedMethod(){return35;}privateanotherUsedMethod(){return7;}anotherMethod(){returnthis.#usedMethod()+this.anotherUsedMethod();}}classFoo{get #usedAccessor(){}set #usedAccessor(value){}privategetanotherUsedAccessor(){}privatesetanotherUsedAccessor(value){}method(){this.#usedAccessor=42;this.anotherUsedAccessor=42;}}