Linter · Rules
no-unused-private-class-members
Disallow #private class members that are never used
Nothing outside a class can reach its #private fields and methods. If nothing inside the class uses one either, it's dead code, or the code that should use it is missing.
A field that's only written to counts as unused, because the statements this.#count = 1 and this.#count++ never read the value.
If nothing refers to the member at all, --fix-suggestions removes it, unless it has a decorator or an initializer that runs other code, like #sent = sendEmail().
This rule is on by default.
Configure
On by default as a warning. To turn it off:
[lint.rules]
"no-unused-private-class-members" = "off" # or "error"
Examples
Reported:
class Counter {
#count = 0;
#step = 1;
#log() {
console.log("changed");
}
increment() {
this.#count++;
}
}
Not reported:
class Counter {
#count = 0;
#step = 1;
#log() {
console.log("changed to", this.#count);
}
increment() {
this.#count += this.#step;
this.#log();
}
}
In TypeScript files, setting this rule runs @typescript-eslint/no-unused-private-class-members instead. It also checks private members:
class Counter {
private count = 0;
}