unicorn/no-static-only-class Pedantic
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.
Examples
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() {}
}How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-static-only-class": "error"
}
}bash
oxlint --deny unicorn/no-static-only-class