This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3160efa
commit 28e5351
Showing
17 changed files
with
9,067 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
862 changes: 862 additions & 0 deletions
862
crates/rome_js_analyze/src/analyzers/js/use_optional_chain.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
crates/rome_js_analyze/tests/specs/js/useOptionalChain/complexLogicalAndCases.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// currently do not handle complex computed properties | ||
foo && foo[bar as string] && foo[bar as string].baz; | ||
foo && foo[1 + 2] && foo[1 + 2].baz; | ||
foo && foo[typeof bar] && foo[typeof bar].baz; |
69 changes: 69 additions & 0 deletions
69
crates/rome_js_analyze/tests/specs/js/useOptionalChain/complexLogicalAndCases.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
source: crates/rome_js_analyze/tests/spec_tests.rs | ||
expression: complexLogicalAndCases.ts | ||
--- | ||
# Input | ||
```js | ||
// currently do not handle complex computed properties | ||
foo && foo[bar as string] && foo[bar as string].baz; | ||
foo && foo[1 + 2] && foo[1 + 2].baz; | ||
foo && foo[typeof bar] && foo[typeof bar].baz; | ||
``` | ||
|
||
# Diagnostics | ||
``` | ||
warning[js/useOptionalChain]: Change to an optional chain. | ||
┌─ complexLogicalAndCases.ts:2:1 | ||
│ | ||
2 │ foo && foo[bar as string] && foo[bar as string].baz; | ||
│ ------------------------- | ||
Suggested fix: Change to an optional chain. | ||
| @@ -1,4 +1,4 @@ | ||
0 0 | // currently do not handle complex computed properties | ||
1 | - foo && foo[bar as string] && foo[bar as string].baz; | ||
1 | + foo?.[bar as string] && foo[bar as string].baz; | ||
2 2 | foo && foo[1 + 2] && foo[1 + 2].baz; | ||
3 3 | foo && foo[typeof bar] && foo[typeof bar].baz; | ||
``` | ||
|
||
``` | ||
warning[js/useOptionalChain]: Change to an optional chain. | ||
┌─ complexLogicalAndCases.ts:3:1 | ||
│ | ||
3 │ foo && foo[1 + 2] && foo[1 + 2].baz; | ||
│ ----------------- | ||
Suggested fix: Change to an optional chain. | ||
| @@ -1,4 +1,4 @@ | ||
0 0 | // currently do not handle complex computed properties | ||
1 1 | foo && foo[bar as string] && foo[bar as string].baz; | ||
2 | - foo && foo[1 + 2] && foo[1 + 2].baz; | ||
2 | + foo?.[1 + 2] && foo[1 + 2].baz; | ||
3 3 | foo && foo[typeof bar] && foo[typeof bar].baz; | ||
``` | ||
|
||
``` | ||
warning[js/useOptionalChain]: Change to an optional chain. | ||
┌─ complexLogicalAndCases.ts:4:1 | ||
│ | ||
4 │ foo && foo[typeof bar] && foo[typeof bar].baz; | ||
│ ---------------------- | ||
Suggested fix: Change to an optional chain. | ||
| @@ -1,4 +1,4 @@ | ||
0 0 | // currently do not handle complex computed properties | ||
1 1 | foo && foo[bar as string] && foo[bar as string].baz; | ||
2 2 | foo && foo[1 + 2] && foo[1 + 2].baz; | ||
3 | - foo && foo[typeof bar] && foo[typeof bar].baz; | ||
3 | + foo?.[typeof bar] && foo[typeof bar].baz; | ||
``` | ||
|
||
|
Oops, something went wrong.