no-useless-constructor
Disallow unnecessary constructors
💡 hasSuggestions
Some problems reported by this rule are manually fixable by editor suggestions
ES2015 provides a default class constructor if one is not specified. As such, it is unnecessary to provide an empty constructor or one that simply delegates into its parent class, as in the following examples:
class A {
constructor () {
}
}
class B extends A {
constructor (value) {
super(value);
}
}
Rule Details
This rule flags class constructors that can be safely removed without changing how the class works.
Examples
Examples of incorrect code for this rule:
Open in Playground
/*eslint no-useless-constructor: "error"*/
class A {
}
class B extends A {
}
Examples of correct code for this rule:
Open in Playground
/*eslint no-useless-constructor: "error"*/
class A { }
class B {
constructor () {
doSomething();
}
}
class C extends A {
constructor() {
super('foo');
}
}
class D extends A {
constructor() {
super();
doSomething();
}
}
When Not To Use It
If you don’t want to be notified about unnecessary constructors, you can safely disable this rule.
Version
This rule was introduced in ESLint v2.0.0-beta.1.