Disallow unused private class members
Using the recommended config from @eslint/js in a configuration file enables this rule
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.
This rule reports unused private class members.
Examples of incorrect code for this rule:
/*eslint no-unused-private-class-members: "error"*/
class A {
= 5;
}
class B {
= 5;
method() {
this.#usedOnlyInWrite = 42;
}
}
class C {
= 5;
method() {
this.#usedOnlyToUpdateItself++;
}
}
class D {
() {}
}
class E {
get #unusedAccessor() {}
set (value) {}
}
Examples of correct code for this rule:
/*eslint no-unused-private-class-members: "error"*/
class A {
#usedMember = 42;
method() {
return this.#usedMember;
}
}
class B {
#usedMethod() {
return 42;
}
anotherMethod() {
return this.#usedMethod();
}
}
class C {
get #usedAccessor() {}
set #usedAccessor(value) {}
method() {
this.#usedAccessor = 42;
}
}
This rule has no options.
If you don’t want to be notified about unused private class members, you can safely turn this rule off.
This rule was introduced in ESLint v8.1.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/no-unused-private-class-members