Skip to content

unicorn/no-static-only-class Pedantic

🚧 An auto-fix is still under development.

What it does

Disallow classes that only have static members.

Why is this bad?

A class with only static members could just be an object instead.

Example

Examples of incorrect code for this rule:

javascript
class A {
  static a() {}
}

Examples of correct code for this rule:

javascript
class A {
  static a() {}

  constructor() {}
}
javascript
const X = {
  foo: false,
  bar() {},
};
javascript
class X {
  static #foo = false; // private field
  static bar() {}
}

References

Released under the MIT License.