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

fix(rome_js_analyze): suppress false positive diagnostics to nested if statements #4614

Merged
merged 2 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ multiple files:
React introduce new directives, "use client" and "use server".
The rule raises false positive errors about these directives.

- Fix false positive diagnostics ([#4483](https://github.com/rome/tools/issues/4483)) that [`NoUnreachableSuper`](https://docs.rome.tools/lint/rules/nounreachablesuper/) caused to nested if statement.

The rule no longer reports `This constructor calls super() in a loop`
when using nested if statements in a constructor.

### Parser

### VSCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,8 @@ impl Rule for NoUnreachableSuper {
.insert(prev_block, super_expression)
.filter(|previous_node| *previous_node == super_expression);

if let Some(previous_node) = previous_node {
return Some(RuleState::DuplicateSuper {
first: previous_node.syntax().text_trimmed_range(),
second: super_expression.syntax().text_trimmed_range(),
});
if previous_node.is_some() {
continue;
}

if let Some(outgoing_edges) = outgoing_edges.get(block_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ class G extends A {
this.field = "value";
}
}

// valid
class H extends A {
constructor() {
super();
if (flag1) {
if (flag2) {
console.log("This is not a loop.");
}
}
}
}

// invalid
class I extends A {
constructor() {
super();
if (flag1) {
if (flag2) {
super();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 96
expression: missingSuper.js
---
# Input
Expand Down Expand Up @@ -79,6 +78,30 @@ class G extends A {
}
}

// valid
class H extends A {
constructor() {
super();
if (flag1) {
if (flag2) {
console.log("This is not a loop.");
}
}
}
}

// invalid
class I extends A {
constructor() {
super();
if (flag1) {
if (flag2) {
super();
}
}
}
}

```

# Diagnostics
Expand Down Expand Up @@ -157,4 +180,42 @@ missingSuper.js:41:5 lint/correctness/noUnreachableSuper ━━━━━━━

```

```
missingSuper.js:89:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! This constructor has code paths where `super()` is called more than once.

87 │ // invalid
88 │ class I extends A {
> 89 │ constructor() {
│ ^^^^^^^^^^^^^^^
> 90 │ super();
...
> 95 │ }
> 96 │ }
│ ^
97 │ }
98 │

i `super()` is first called here:

88 │ class I extends A {
89 │ constructor() {
> 90 │ super();
│ ^^^^^
91 │ if (flag1) {
92 │ if (flag2) {

i `super()` is then called again here:

91 │ if (flag1) {
92 │ if (flag2) {
> 93 │ super();
│ ^^^^^
94 │ }
95 │ }


```