noUnreachableSuper
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/correctness/noUnreachableSuper
Since: v1.0.0
Sources:
- Same as:
no-this-before-super
Ensures the super()
constructor is called exactly once on every code path in a class constructor before this
is accessed if the class has a superclass
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This constructor has code paths that return without calling </span><span style="color: Tomato;"><strong>super()</strong></span><span style="color: Tomato;">
.
1 │ class A extends B {
> 2 │ constructor() {}
│ ^^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ If this is intentional, add an explicit throw statement in unsupported paths.
code-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This constructor has code paths accessing </span><span style="color: Tomato;"><strong>this</strong></span><span style="color: Tomato;">
without calling </span><span style="color: Tomato;"><strong>super()</strong></span><span style="color: Tomato;">
first.
1 │ class A extends B {
> 2 │ constructor(value) {
│ ^^^^^^^^^^^^^^^^^^^^
> 3 │ this.prop = value;
> 4 │ super();
> 5 │ }
│ ^
6 │ }
7 │
ℹ </span><span style="color: lightgreen;"><strong>this</strong></span><span style="color: lightgreen;">
is accessed here:
1 │ class A extends B {
2 │ constructor(value) {
> 3 │ this.prop = value;
│ ^^^^
4 │ super();
5 │ }
ℹ If this is intentional, add an explicit throw statement in unsupported paths.
code-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This constructor has code paths that return without calling </span><span style="color: Tomato;"><strong>super()</strong></span><span style="color: Tomato;">
.
1 │ class A extends B {
> 2 │ constructor(cond) {
│ ^^^^^^^^^^^^^^^^^^^
> 3 │ if(cond) {
> 4 │ super();
> 5 │ }
> 6 │ }
│ ^
7 │ }
8 │
ℹ If this is intentional, add an explicit throw statement in unsupported paths.