31 lines
806 B
Plaintext
31 lines
806 B
Plaintext
== Why is this an issue?
|
|
|
|
If the class declaration does not include a constructor, one is automatically created, so there is no need to provide an empty constructor, or one that just delegates to the parent class.
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
class Foo {
|
|
constructor() {} // Noncompliant, empty
|
|
}
|
|
|
|
class Bar extends Foo {
|
|
constructor(params) { // Noncompliant: just delegates to the parent
|
|
super(params);
|
|
}
|
|
}
|
|
----
|
|
|
|
Instead, you can safely remove the empty constructor without affecting the functionality.
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
----
|
|
class Foo {}
|
|
|
|
class Bar extends Foo {}
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor[constructor]
|