-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(analyzer): False positive in rule noUndeclaredVariables #243
- Loading branch information
1 parent
55f740c
commit 8acf9be
Showing
13 changed files
with
180 additions
and
11 deletions.
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredVariables/infer.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,5 @@ | ||
export type WithSelectors<S> = S extends { getState: () => infer T } | ||
? S & { use: { [K in keyof T]: () => T[K] } } | ||
: never; | ||
|
||
type A = number extends infer T ? T : never; |
15 changes: 15 additions & 0 deletions
15
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredVariables/infer.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,15 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: infer.ts | ||
--- | ||
# Input | ||
```js | ||
export type WithSelectors<S> = S extends { getState: () => infer T } | ||
? S & { use: { [K in keyof T]: () => T[K] } } | ||
: never; | ||
|
||
type A = number extends infer T ? T : never; | ||
|
||
``` | ||
|
||
|
1 change: 1 addition & 0 deletions
1
crates/biome_js_analyze/tests/specs/correctness/noUndeclaredVariables/infer_incorrect.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 @@ | ||
type A = number extends infer T ? never : T; |
24 changes: 24 additions & 0 deletions
24
...es/biome_js_analyze/tests/specs/correctness/noUndeclaredVariables/infer_incorrect.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,24 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: infer_incorrect.ts | ||
--- | ||
# Input | ||
```js | ||
type A = number extends infer T ? never : T; | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
infer_incorrect.ts:1:43 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! The T variable is undeclared | ||
> 1 │ type A = number extends infer T ? never : T; | ||
│ ^ | ||
2 │ | ||
``` | ||
|
||
|
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
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
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,8 @@ | ||
use crate::assert_semantics; | ||
|
||
assert_semantics! { | ||
ok_conditional_true_type_scope, "type A<T> = T extends string ? (/*START Scope*/number)/*END Scope*/: boolean;", | ||
ok_conditional_true_type_infer_simple, "type A<T> = T extends infer /*@ Scope */T ? (/*START Scope*/number)/*END Scope*/: boolean;", | ||
ok_conditional_true_type_infer_function, "type A<T> = T extends { getState: () => infer /*@ Scope */ T } ? (/*START Scope*/number)/*END Scope*/: boolean;", | ||
ok_conditional_true_type_infer_nested, "type A = MyType extends (OtherType extends infer /*@ InnerScope */T ? (/*START InnerScope*/infer /*@ OuterScope */ U)/*END InnerScope*/ : InnerFalse) ? (/*START OuterScope*/OuterTrue)/*END OuterScope*/ : OuterFalse;", | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod assertions; | ||
pub mod declarations; | ||
mod functions; | ||
mod infer; | ||
mod references; | ||
mod scopes; | ||
|
||
|
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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