Skip to content

Commit 2d0b8e6

Browse files
authored
refactor: use semantic model for module graph (#9211)
1 parent b49707c commit 2d0b8e6

File tree

93 files changed

+1577
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1577
-483
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7905](https://github.com/biomejs/biome/issues/7905). Improved the accuracy of type-aware lint rules when analyzing re-exported functions and values.
6+
7+
Previously, when a binding was imported from another module, its type was not correctly inferred during the type analysis phase. This caused type-aware lint rules to fail to detect issues when working with re-exported imports.
8+
9+
The following rules now correctly handle re-exported imports:
10+
- [`useAwaitThenable`](https://biomejs.dev/linter/rules/use-await-thenable/)
11+
- [`noFloatingPromises`](https://biomejs.dev/linter/rules/no-floating-promises/)
12+
- [`noMisusedPromises`](https://biomejs.dev/linter/rules/no-misused-promises/)
13+
- [`useArraySortCompare`](https://biomejs.dev/linter/rules/use-array-sort-compare/)
14+
15+
Example of now-working detection:
16+
17+
```ts
18+
// getValue.ts
19+
export async function getValue(): Promise<number> {
20+
return 42;
21+
}
22+
23+
// reexport.ts
24+
export { getValue } from "./getValue";
25+
26+
// index.ts
27+
import { getValue } from "./reexport";
28+
29+
// Previously: no diagnostic (type was unknown)
30+
// Now: correctly detects that getValue() returns a Promise
31+
await getValue(); // Valid - properly awaited
32+
getValue(); // Diagnostic - floating promise
33+
```

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* should not generate diagnostics */
2+
3+
export async function getValue(): Promise<number> {
4+
return 42;
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: getValue.ts
4+
---
5+
# Input
6+
```ts
7+
/* should not generate diagnostics */
8+
9+
export async function getValue(): Promise<number> {
10+
return 42;
11+
}
12+
13+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* should generate diagnostics */
2+
3+
import { getValue } from "./reexport";
4+
5+
function test() {
6+
// Invalid: Promise is not handled (no await, no .then, no void operator)
7+
getValue();
8+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: index.ts
4+
---
5+
# Input
6+
```ts
7+
/* should generate diagnostics */
8+
9+
import { getValue } from "./reexport";
10+
11+
function test() {
12+
// Invalid: Promise is not handled (no await, no .then, no void operator)
13+
getValue();
14+
}
15+
16+
```
17+
18+
# Diagnostics
19+
```
20+
index.ts:7:5 lint/nursery/noFloatingPromises ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
21+
22+
i A "floating" Promise was found, meaning it is not properly handled and could lead to ignored errors or unexpected behavior.
23+
24+
5 │ function test() {
25+
6// Invalid: Promise is not handled (no await, no .then, no void operator)
26+
> 7getValue();
27+
^^^^^^^^^^^
28+
8}
29+
9 │
30+
31+
i This happens when a Promise is not awaited, lacks a `.catch` or `.then` rejection handler, or is not explicitly ignored using the `void` operator.
32+
33+
i This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
34+
35+
36+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* should not generate diagnostics */
2+
3+
export { getValue } from "./getValue";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: reexport.ts
4+
---
5+
# Input
6+
```ts
7+
/* should not generate diagnostics */
8+
9+
export { getValue } from "./getValue";
10+
11+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* should not generate diagnostics */
2+
3+
export async function getValue(): Promise<number> {
4+
return 42;
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: getValue.ts
4+
---
5+
# Input
6+
```ts
7+
/* should not generate diagnostics */
8+
9+
export async function getValue(): Promise<number> {
10+
return 42;
11+
}
12+
13+
```

0 commit comments

Comments
 (0)