no-unused-private-class-members
Disallow #private class members that are never used
warn by defaulthas suggestions
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:
bunfig.toml
[lint.rules]
"no-unused-private-class-members" = "off" # or "error"Examples#
example.js3 problems
class Counter {
#count#count is defined but never used. = 0;
#step#step is defined but never used. = 1;
#log#log is defined but never used.() {
console.log("changed");
}
increment() {
this.#count++;
}
}example.jsNo problems
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:
example.ts1 problem
class Counter {
private countPrivate class member count is defined but never used. = 0;
}