Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
improve the diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Dec 20, 2022
1 parent 0dad1db commit 9977d00
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,46 +235,59 @@ impl Rule for NoUnreachableSuper {
RuleState::ThisBeforeSuper { this, super_ } => Some(
RuleDiagnostic::new(
rule_category!(),
*this,
markup! { "`"<Emphasis>"this"</Emphasis>"` is accessed before `"<Emphasis>"super()"</Emphasis>"` is called." },
ctx.query().node.text_trimmed_range(),
markup! { "This constructor has code paths accessing `"<Emphasis>"this"</Emphasis>"` before `"<Emphasis>"super()"</Emphasis>"` is called." },
)
.detail(super_, markup! { "`"<Emphasis>"super()"</Emphasis>"` is only called here" }),
.detail(this, markup! { "`"<Emphasis>"this"</Emphasis>"` is accessed here:" })
.detail(super_, markup! { "`"<Emphasis>"super()"</Emphasis>"` is only called here:" })
.note("If this is intentional, add an explicit throw statement in unsupported paths."),
),


RuleState::ThisWithoutSuper { this } => Some(
RuleDiagnostic::new(
rule_category!(),
ctx.query().node.text_trimmed_range(),
markup! { "This constructor has code paths accessing `"<Emphasis>"this"</Emphasis>"` without calling `"<Emphasis>"super()"</Emphasis>"` first." },
)
.detail(this, markup! { "`"<Emphasis>"this"</Emphasis>"` is accessed here:" })
.note("If this is intentional, add an explicit throw statement in unsupported paths."),
),

RuleState::DuplicateSuper { first, second } if *first == *second => Some(
RuleDiagnostic::new(
rule_category!(),
second,
markup! { "`"<Emphasis>"super()"</Emphasis>"` is called in a loop." },
),
ctx.query().node.text_trimmed_range(),
markup! { "This constructor calls `"<Emphasis>"super()"</Emphasis>"` in a loop." },
)
.detail(first, markup! { "`"<Emphasis>"super()"</Emphasis>"` is called here:" }),
),
RuleState::DuplicateSuper { first, second } => Some(
RuleDiagnostic::new(
rule_category!(),
second,
markup! { "`"<Emphasis>"super()"</Emphasis>"` is called more than once." },
ctx.query().node.text_trimmed_range(),
markup! { "This constructor has code paths where `"<Emphasis>"super()"</Emphasis>"` is called more than once." },
)
.detail(first, markup! { "`"<Emphasis>"super()"</Emphasis>"` has already been called here" }),
.detail(first, markup! { "`"<Emphasis>"super()"</Emphasis>"` is first called here:" })
.detail(second, markup! { "`"<Emphasis>"super()"</Emphasis>"` is then called again here:" }),
),

RuleState::ThisWithoutSuper { this } => Some(RuleDiagnostic::new(
rule_category!(),
*this,
markup! { "`"<Emphasis>"this"</Emphasis>"` is accessed without calling `"<Emphasis>"super()"</Emphasis>"` first." },
)),

RuleState::ReturnWithoutSuper {
return_: Some(range),
} => Some(RuleDiagnostic::new(
rule_category!(),
*range,
markup! { "This statement returns from the constructor without having called `"<Emphasis>"super()"</Emphasis>"` first." },
)),
RuleState::ReturnWithoutSuper { return_: None } => Some(RuleDiagnostic::new(
rule_category!(),
ctx.query().node.text_trimmed_range(),
markup! { "This constructor returns without calling `"<Emphasis>"super()"</Emphasis>"`." },
)),
RuleState::ReturnWithoutSuper { return_: Some(range) } => Some(
RuleDiagnostic::new(
rule_category!(),
ctx.query().node.text_trimmed_range(),
markup! { "This constructor has code paths that return without calling `"<Emphasis>"super()"</Emphasis>"` first." },
)
.detail(range, markup! { "This statement returns from the constructor before `"<Emphasis>"super()"</Emphasis>"` has been called:" })
.note("If this is intentional, add an explicit throw statement in unsupported paths."),
),
RuleState::ReturnWithoutSuper { return_: None } => Some(
RuleDiagnostic::new(
rule_category!(),
ctx.query().node.text_trimmed_range(),
markup! { "This constructor has code paths that return without calling `"<Emphasis>"super()"</Emphasis>"`." },
)
.note("If this is intentional, add an explicit throw statement in unsupported paths."),
),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,22 @@ class G extends A {

# Diagnostics
```
duplicateSuper.js:16:9 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
duplicateSuper.js:14:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! `super()` is called more than once.
! This constructor has code paths where `super()` is called more than once.
14 │ constructor() {
15 │ super(1);
12 │ // invalid
13 │ class C extends A {
> 14 │ constructor() {
│ ^^^^^^^^^^^^^^^
> 15 │ super(1);
> 16 │ super(2);
^^^^^
17 }
> 17 }
^
18 │ }
19 │
i `super()` has already been called here
i `super()` is first called here:
13 │ class C extends A {
14 │ constructor() {
Expand All @@ -90,22 +94,36 @@ duplicateSuper.js:16:9 lint/nursery/noUnreachableSuper ━━━━━━━━
16 │ super(2);
17 │ }
i `super()` is then called again here:
14 │ constructor() {
15 │ super(1);
> 16 │ super(2);
│ ^^^^^
17 │ }
18 │ }
```

```
duplicateSuper.js:27:9 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
duplicateSuper.js:22:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! `super()` is called more than once.
! This constructor has code paths where `super()` is called more than once.
25 │ }
26 │
20 │ // invalid
21 │ class D extends A {
> 22 │ constructor(cond) {
│ ^^^^^^^^^^^^^^^^^^^
> 23 │ if (cond) {
...
> 27 │ super();
^^^^^
28 }
> 28 }
^
29 │ }
30 │
i `super()` has already been called here
i `super()` is first called here:
22 │ constructor(cond) {
23 │ if (cond) {
Expand All @@ -114,13 +132,36 @@ duplicateSuper.js:27:9 lint/nursery/noUnreachableSuper ━━━━━━━━
25 │ }
26 │
i `super()` is then called again here:
25 │ }
26 │
> 27 │ super();
│ ^^^^^
28 │ }
29 │ }
```

```
duplicateSuper.js:35:13 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
duplicateSuper.js:33:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! `super()` is called in a loop.
! This constructor calls `super()` in a loop.
31 │ // invalid
32 │ class E extends A {
> 33 │ constructor(cond) {
│ ^^^^^^^^^^^^^^^^^^^
> 34 │ do {
> 35 │ super();
> 36 │ } while (cond);
> 37 │ }
│ ^
38 │ }
39 │
i `super()` is called here:
33 │ constructor(cond) {
34 │ do {
Expand All @@ -133,18 +174,23 @@ duplicateSuper.js:35:13 lint/nursery/noUnreachableSuper ━━━━━━━━
```

```
duplicateSuper.js:47:13 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
duplicateSuper.js:42:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! `super()` is called more than once.
! This constructor has code paths where `super()` is called more than once.
45 │ }
46 │ if (condB) {
> 47 │ super(true);
│ ^^^^^
48 │ }
49 │ }
40 │ // invalid
41 │ class F extends A {
> 42 │ constructor(condA, condB) {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 43 │ if (condA) {
...
> 48 │ }
> 49 │ }
│ ^
50 │ }
51 │
i `super()` has already been called here
i `super()` is first called here:
42 │ constructor(condA, condB) {
43 │ if (condA) {
Expand All @@ -153,13 +199,36 @@ duplicateSuper.js:47:13 lint/nursery/noUnreachableSuper ━━━━━━━━
45 │ }
46 │ if (condB) {
i `super()` is then called again here:
45 │ }
46 │ if (condB) {
> 47 │ super(true);
│ ^^^^^
48 │ }
49 │ }
```

```
duplicateSuper.js:57:17 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! `super()` is called in a loop.
duplicateSuper.js:54:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This constructor calls `super()` in a loop.
52 │ // invalid
53 │ class G extends A {
> 54 │ constructor(condA, condB) {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 55 │ while (condA) {
...
> 59 │ }
> 60 │ }
│ ^
61 │ }
62 │
i `super()` is called here:
55 │ while (condA) {
56 │ if (condB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class G extends A {
```
missingSuper.js:19:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This constructor returns without calling `super()`.
! This constructor has code paths that return without calling `super()`.
17 │ // invalid
18 │ class C extends A {
Expand All @@ -98,13 +98,15 @@ missingSuper.js:19:5 lint/nursery/noUnreachableSuper ━━━━━━━━━
24 │ }
25 │
i If this is intentional, add an explicit throw statement in unsupported paths.
```

```
missingSuper.js:28:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This constructor returns without calling `super()`.
! This constructor has code paths that return without calling `super()`.
26 │ // invalid
27 │ class D extends A {
Expand All @@ -118,13 +120,29 @@ missingSuper.js:28:5 lint/nursery/noUnreachableSuper ━━━━━━━━━
37 │ }
38 │
i If this is intentional, add an explicit throw statement in unsupported paths.
```

```
missingSuper.js:43:13 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
missingSuper.js:41:5 lint/nursery/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! This statement returns from the constructor without having called `super()` first.
! This constructor has code paths that return without calling `super()` first.
39 │ // invalid
40 │ class E extends A {
> 41 │ constructor(cond) {
│ ^^^^^^^^^^^^^^^^^^^
> 42 │ if (cond) {
...
> 46 │ super(true);
> 47 │ }
│ ^
48 │ }
49 │
i This statement returns from the constructor before `super()` has been called:
41 │ constructor(cond) {
42 │ if (cond) {
Expand All @@ -133,6 +151,8 @@ missingSuper.js:43:13 lint/nursery/noUnreachableSuper ━━━━━━━━
44 │ }
45 │
i If this is intentional, add an explicit throw statement in unsupported paths.
```

Expand Down
Loading

0 comments on commit 9977d00

Please sign in to comment.