Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/docs/guide/usage/linter/rules/eslint/for-direction.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ infinite `for` loop is a bug.

This rule forbids `for` loops where the counter variable changes in such a
way that the stop condition will never be met. For example, if the
counter variable is increasing (i.e. `i++``) and the stop condition tests
that the counter is greater than zero (`i >= 0``) then the loop will never
counter variable is increasing (i.e. `i++`) and the stop condition tests
that the counter is greater than zero (`i >= 0`) then the loop will never
exit.

### Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ It increase cognitive complexity and may impact performance.
Examples of **incorrect** code for this rule:

```ts
function f(a: number, b: number): number {
if (a == 0) {
return 1;
} else {
return f(a - 1, b + 1);
}
function test(only_used_in_recursion) {
return test(only_used_in_recursion);
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/promise/avoid-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Disallow creating promises with `new Promise()`.
Many cases that use `new Promise()` could be refactored to use an
`async` function. `async` is considered more idiomatic in modern JavaScript.

### Example
### Examples

Examples of **incorrect** code for this rule:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Not catching errors in a promise can cause hard to debug problems or
missing handling of error conditions. In the worst case, unhandled
promise rejections can cause your application to crash.

### Example
### Examples

Examples of **incorrect** code for this rule:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Disallows calling new on static `Promise` methods.
Calling a static `Promise` method with `new` is invalid and will result
in a `TypeError` at runtime.

### Example
### Examples

Examples of **incorrect** code for this rule:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ Disallow return statements in a finally() callback of a promise.
Disallow return statements inside a callback passed to finally(), since nothing would
consume what's returned.

### Example
### Examples

Examples of **incorrect** code for this rule:

```javascript
myPromise.finally(function (val) {
return val;
});
```

Examples of **correct** code for this rule:

```javascript
Promise.resolve(1).finally(() => {
console.log(2);
});
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/promise/no_return_in_finally.rs)
10 changes: 9 additions & 1 deletion src/docs/guide/usage/linter/rules/promise/param-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ avoid confusion with order such as reject, resolve. The Promise constructor uses
RevealingConstructor pattern. Using the same parameter names as the language specification
makes code more uniform and easier to understand.

### Example
### Examples

Examples of **incorrect** code for this rule:

```javascript
new Promise(function (reject, resolve) {
Expand All @@ -27,6 +29,12 @@ new Promise(function (ok, fail) {
}); // non-standard parameter names
```

Examples of **correct** code for this rule:

```javascript
new Promise(function (resolve, reject) {});
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/promise/param_names.rs)
16 changes: 14 additions & 2 deletions src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@ Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values

Async/await syntax can be seen as more readable.

### Example
### Examples

Examples of **incorrect** code for this rule:

```javascript
function foo() {
hey.then((x) => {});
}
```

Examples of **correct** code for this rule:

```javascript
myPromise.then(doSomething);
async function hi() {
await thing();
}
```

## References
Expand Down
10 changes: 9 additions & 1 deletion src/docs/guide/usage/linter/rules/promise/valid-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ Enforces the proper number of arguments are passed to Promise functions.
Calling a Promise function with the incorrect number of arguments can lead to unexpected
behavior or hard to spot bugs.

### Example
### Examples

Examples of **incorrect** code for this rule:

```javascript
Promise.resolve(1, 2);
```

Examples of **correct** code for this rule:

```javascript
Promise.resolve(1);
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/promise/valid_params.rs)