pve-eslint/eslint/docs/rules/no-useless-constructor.md
Dominik Csapak eb39fafa4f first commit
includes a (minimal) working wrapper

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-04-06 15:06:03 +02:00

72 lines
1.2 KiB
Markdown

# Disallow unnecessary constructor (no-useless-constructor)
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:
```js
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:
```js
/*eslint no-useless-constructor: "error"*/
/*eslint-env es6*/
class A {
constructor () {
}
}
class B extends A {
constructor (...args) {
super(...args);
}
}
```
Examples of **correct** code for this rule:
```js
/*eslint no-useless-constructor: "error"*/
class A { }
class A {
constructor () {
doSomething();
}
}
class B extends A {
constructor() {
super('foo');
}
}
class B 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.