Skip to content

Commit f3aee1a

Browse files
authored
fix(core): implement constructor parameter property tracking (#8346)
1 parent 111ff34 commit f3aee1a

File tree

6 files changed

+348
-51
lines changed

6 files changed

+348
-51
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#8292](https://github.com/biomejs/biome/issues/8292): Implement tracking
6+
of types of TypeScript constructor parameter properties.
7+
8+
This resolves certain false negatives in `noFloatingPromises` and other typed
9+
rules.
10+
11+
#### Example
12+
13+
```ts
14+
class AsyncClass {
15+
async returnsPromise() {
16+
return 'value';
17+
}
18+
}
19+
20+
class ShouldBeReported {
21+
constructor(public field: AsyncClass) { }
22+
// ^^^^^^^^^^^^----------------- Parameter property declaration
23+
24+
async shouldBeReported() {
25+
// `noFloatingPromises` will now report the following usage:
26+
this.field.returnsPromise();
27+
}
28+
}
29+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* should generate diagnostics */
2+
3+
class AsyncClass {
4+
async returnsPromise() {
5+
return 'value';
6+
}
7+
}
8+
9+
class ShouldBeReported {
10+
constructor(public field: AsyncClass) { }
11+
12+
async shouldBeReported() {
13+
this.field.returnsPromise();
14+
}
15+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: issue8292.ts
4+
---
5+
# Input
6+
```ts
7+
/* should generate diagnostics */
8+
9+
class AsyncClass {
10+
async returnsPromise() {
11+
return 'value';
12+
}
13+
}
14+
15+
class ShouldBeReported {
16+
constructor(public field: AsyncClass) { }
17+
18+
async shouldBeReported() {
19+
this.field.returnsPromise();
20+
}
21+
}
22+
23+
```
24+
25+
# Diagnostics
26+
```
27+
issue8292.ts:13:9 lint/nursery/noFloatingPromises FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
28+
29+
i A "floating" Promise was found, meaning it is not properly handled and could lead to ignored errors or unexpected behavior.
30+
31+
12 │ async shouldBeReported() {
32+
> 13this.field.returnsPromise();
33+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
14}
35+
15 │ }
36+
37+
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.
38+
39+
i Unsafe fix: Add await operator.
40+
41+
13 │ ········await·this.field.returnsPromise();
42+
│ ++++++
43+
44+
```

0 commit comments

Comments
 (0)