# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-unused-private-class-members" = "off" # or "error"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```js
class Counter {
  #count = 0;
  #step = 1;

  #log() {
    console.log("changed");
  }

  increment() {
    this.#count++;
  }
}
```

Not reported:

{/* good */}
```js
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:

{/* bad */}
```ts
class Counter {
  private count = 0;
}
```
