There is no good excuse for an empty class. If it’s being used simply as a common extension point, it should be replaced with an
interface
. If it was stubbed in as a placeholder for future development it should be fleshed-out. In any other case, it should be
eliminated.
Additionally, one shouldn’t use a class to define exclusively static methods. Instead one can use a module, or better, export each function
separately.
Why is this an issue?
Using an empty class serves no purpose and can hinder the readability of the code.
class Foo {
static bar() {
// ...
}
}
How to fix it
You can export the functions that you wish to make available.
export function bar() {
// ...
}
Code examples
Noncompliant code example
class Foo { // Noncompliant
static bar() {
// ...
}
}
Compliant solution
export function bar() {
// ...
}
Noncompliant code example
class DoAndLog { // Noncompliant
constructor () {
console.log('I\'m done!');
}
}
Compliant solution
function doAndLog() {
console.log('I\'m done!');
}