Skip to content

Commit 401beae

Browse files
oxc-botcamc314
andauthored
Release 1.11.0 (#440)
* Release 1.11.0 * hide type aware cli glag --------- Co-authored-by: Cameron Clark <[email protected]>
1 parent 0188b31 commit 401beae

File tree

4 files changed

+196
-3
lines changed

4 files changed

+196
-3
lines changed

src/docs/guide/usage/linter/generated-rules.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The progress of all rule implementations is tracked [here](https://github.com/oxc-project/oxc/issues/481).
44

5-
- Total number of rules: 528
5+
- Total number of rules: 530
66
- Rules turned on by default: 88
77

88
**Legend for 'Fixable?' column:**
@@ -290,7 +290,7 @@ Lints which prevent the use of language and library features. Must not be enable
290290
| [prefer-node-protocol](/docs/guide/usage/linter/rules/unicorn/prefer-node-protocol.html) | unicorn | | 🛠️ |
291291
| [prefer-number-properties](/docs/guide/usage/linter/rules/unicorn/prefer-number-properties.html) | unicorn | | ⚠️🛠️️ |
292292

293-
## Suspicious (33):
293+
## Suspicious (35):
294294

295295
code that is most likely wrong or useless.
296296

@@ -323,6 +323,8 @@ code that is most likely wrong or useless.
323323
| [style-prop-object](/docs/guide/usage/linter/rules/react/style-prop-object.html) | react | | |
324324
| [no-confusing-non-null-assertion](/docs/guide/usage/linter/rules/typescript/no-confusing-non-null-assertion.html) | typescript | | 🚧 |
325325
| [no-extraneous-class](/docs/guide/usage/linter/rules/typescript/no-extraneous-class.html) | typescript | | ⚠️💡 |
326+
| [no-floating-promises](/docs/guide/usage/linter/rules/typescript/no-floating-promises.html) | typescript | | 🚧 |
327+
| [no-misused-promises](/docs/guide/usage/linter/rules/typescript/no-misused-promises.html) | typescript | | 🚧 |
326328
| [no-unnecessary-type-constraint](/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-constraint.html) | typescript | | |
327329
| [consistent-function-scoping](/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.html) | unicorn | | 🚧 |
328330
| [no-accessor-recursion](/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.html) | unicorn | | |
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->
2+
3+
<script setup>
4+
import { data } from '../version.data.js';
5+
const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/typescript/no_floating_promises.rs`;
6+
</script>
7+
8+
# typescript/no-floating-promises <Badge type="info" text="Suspicious" />
9+
10+
<div class="rule-meta">
11+
<Alert class="fix" type="info">
12+
<span class="emoji">🚧</span> An auto-fix is still under development.
13+
</Alert>
14+
</div>
15+
16+
### What it does
17+
18+
This rule disallows "floating" Promises in TypeScript code, which is a Promise that is created without any code to handle its resolution or rejection.
19+
20+
This rule will report Promise-valued statements that are not treated in one of the following ways:
21+
22+
- Calling its `.then()` with two arguments
23+
- Calling its `.catch()` with one argument
24+
- `await`ing it
25+
- `return`ing it
26+
- `void`ing it
27+
28+
This rule also reports when an Array containing Promises is created and not properly handled. The main way to resolve this is by using one of the Promise concurrency methods to create a single Promise, then handling that according to the procedure above. These methods include:
29+
30+
- `Promise.all()`
31+
- `Promise.allSettled()`
32+
- `Promise.any()`
33+
- `Promise.race()`
34+
35+
### Why is this bad?
36+
37+
Floating Promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections, and more.
38+
39+
### Examples
40+
41+
Examples of **incorrect** code for this rule:
42+
43+
```ts
44+
const promise = new Promise((resolve, reject) => resolve("value"));
45+
promise;
46+
47+
async function returnsPromise() {
48+
return "value";
49+
}
50+
returnsPromise().then(() => {});
51+
52+
Promise.reject("value").catch();
53+
54+
Promise.reject("value").finally();
55+
56+
[1, 2, 3].map(async x => x + 1);
57+
```
58+
59+
Examples of **correct** code for this rule:
60+
61+
```ts
62+
const promise = new Promise((resolve, reject) => resolve("value"));
63+
await promise;
64+
65+
async function returnsPromise() {
66+
return "value";
67+
}
68+
69+
void returnsPromise();
70+
71+
returnsPromise().then(
72+
() => {},
73+
() => {},
74+
);
75+
76+
Promise.reject("value").catch(() => {});
77+
78+
await Promise.reject("value").finally(() => {});
79+
80+
await Promise.all([1, 2, 3].map(async x => x + 1));
81+
```
82+
83+
## How to use
84+
85+
To **enable** this rule in the CLI or using the config file, you can use:
86+
87+
::: code-group
88+
89+
```bash [CLI]
90+
oxlint --deny typescript/no-floating-promises
91+
```
92+
93+
```json [Config (.oxlintrc.json)]
94+
{
95+
"rules": {
96+
"typescript/no-floating-promises": "error"
97+
}
98+
}
99+
```
100+
101+
:::
102+
103+
## References
104+
105+
- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->
2+
3+
<script setup>
4+
import { data } from '../version.data.js';
5+
const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/typescript/no_misused_promises.rs`;
6+
</script>
7+
8+
# typescript/no-misused-promises <Badge type="info" text="Suspicious" />
9+
10+
<div class="rule-meta">
11+
<Alert class="fix" type="info">
12+
<span class="emoji">🚧</span> An auto-fix is still under development.
13+
</Alert>
14+
</div>
15+
16+
### What it does
17+
18+
This rule forbids providing Promises to logical locations such as if statements in places where the TypeScript compiler allows them but they are not handled properly. These situations can often arise due to a missing await keyword or just a misunderstanding of the way async functions are handled/awaited.
19+
20+
### Why is this bad?
21+
22+
Misused promises can cause crashes or other unexpected behavior, unless there are possibly some global unhandled promise handlers registered.
23+
24+
### Examples
25+
26+
Examples of **incorrect** code for this rule:
27+
28+
```ts
29+
// Promises in conditionals:
30+
const promise = Promise.resolve("value");
31+
if (promise) {
32+
// Do something
33+
}
34+
35+
// Promises where `void` return was expected:
36+
[1, 2, 3].forEach(async value => {
37+
await fetch(`/${value}`);
38+
});
39+
40+
// Spreading Promises:
41+
const getData = () => fetch("/");
42+
console.log({ foo: 42, ...getData() });
43+
```
44+
45+
Examples of **correct** code for this rule:
46+
47+
```ts
48+
// Awaiting the Promise to get its value in a conditional:
49+
const promise = Promise.resolve("value");
50+
if (await promise) {
51+
// Do something
52+
}
53+
54+
// Using a `for-of` with `await` inside (instead of `forEach`):
55+
for (const value of [1, 2, 3]) {
56+
await fetch(`/${value}`);
57+
}
58+
59+
// Spreading data returned from Promise, instead of the Promise itself:
60+
const getData = () => fetch("/");
61+
console.log({ foo: 42, ...(await getData()) });
62+
```
63+
64+
## How to use
65+
66+
To **enable** this rule in the CLI or using the config file, you can use:
67+
68+
::: code-group
69+
70+
```bash [CLI]
71+
oxlint --deny typescript/no-misused-promises
72+
```
73+
74+
```json [Config (.oxlintrc.json)]
75+
{
76+
"rules": {
77+
"typescript/no-misused-promises": "error"
78+
}
79+
}
80+
```
81+
82+
:::
83+
84+
## References
85+
86+
- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
22
load() {
3-
return "5f74a0b16069469fcb284b69fc13223edd0b4316";
3+
return "2f8fc31c46ee254a8461ca6eb749442b668f2807";
44
},
55
};

0 commit comments

Comments
 (0)