Unused private fields in a class should be removed

  • UNUSED_PRIVATE_FIELD
  • Code Quality
  • Low
  • es13

This rule applies when private fields and methods are declared in a class but not used in the class body.

For maintainability, it is recommended to remove unused code. Also, it might be a mistake that a programmer forgets to use declared fields and methods.

Noncompliant Code Example

View with compliant examples side by side
class Example {
    #x = 1;
    #unusedField = 2; // UNUSED_PRIVATE_FIELD alarm
    #unusedMethod() { // UNUSED_PRIVATE_FIELD alarm
    }
    foo() {
        doSomething(this.#x);
    }
}

Compliant Code Example

View with noncompliant examples side by side
class Example {
    #x = 1;
    foo() {
        doSomething(this.#x);
    }
}

Version

This rule was introduced in DeepScan 1.49.0.

See

Was this documentation helpful?