no-useless-constructor
Disallow constructors that do what the default constructor does
has suggestions
A class without a constructor gets one for free. In a base class it's empty, and in a subclass it passes all arguments to super(). Writing that out by hand adds lines that do nothing.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-useless-constructor" = "error" # or "warn"Examples#
example.js2 problems
class Store {
constructorUseless constructor.() {}
}
class UserStore extends Store {
constructorUseless constructor.(name, options) {
super(name, options);
}
}example.jsNo problems
class Store {}
class UserStore extends Store {}
class CachedStore extends Store {
constructor(name) {
super(name, { cache: true });
}
}In TypeScript, a constructor is allowed if it's private or protected, or if its parameters declare fields:
example.tsNo problems
class Config {
private constructor() {}
}
class User {
constructor(public name: string) {}
}