diff --git a/src/docs/guide/usage/linter/rules/eslint/for-direction.md b/src/docs/guide/usage/linter/rules/eslint/for-direction.md index 92f881e8e47..9e03e96da1c 100644 --- a/src/docs/guide/usage/linter/rules/eslint/for-direction.md +++ b/src/docs/guide/usage/linter/rules/eslint/for-direction.md @@ -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 diff --git a/src/docs/guide/usage/linter/rules/oxc/only-used-in-recursion.md b/src/docs/guide/usage/linter/rules/oxc/only-used-in-recursion.md index 38c02453121..56ed9fb1823 100644 --- a/src/docs/guide/usage/linter/rules/oxc/only-used-in-recursion.md +++ b/src/docs/guide/usage/linter/rules/oxc/only-used-in-recursion.md @@ -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); } ``` diff --git a/src/docs/guide/usage/linter/rules/promise/avoid-new.md b/src/docs/guide/usage/linter/rules/promise/avoid-new.md index b5aa4197308..563bcedcfbb 100644 --- a/src/docs/guide/usage/linter/rules/promise/avoid-new.md +++ b/src/docs/guide/usage/linter/rules/promise/avoid-new.md @@ -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: diff --git a/src/docs/guide/usage/linter/rules/promise/catch-or-return.md b/src/docs/guide/usage/linter/rules/promise/catch-or-return.md index 3a076bf1288..9e360b25f77 100644 --- a/src/docs/guide/usage/linter/rules/promise/catch-or-return.md +++ b/src/docs/guide/usage/linter/rules/promise/catch-or-return.md @@ -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: diff --git a/src/docs/guide/usage/linter/rules/promise/no-new-statics.md b/src/docs/guide/usage/linter/rules/promise/no-new-statics.md index 287ce33f322..47ecfed42a5 100644 --- a/src/docs/guide/usage/linter/rules/promise/no-new-statics.md +++ b/src/docs/guide/usage/linter/rules/promise/no-new-statics.md @@ -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: diff --git a/src/docs/guide/usage/linter/rules/promise/no-return-in-finally.md b/src/docs/guide/usage/linter/rules/promise/no-return-in-finally.md index 93660587ee8..6b5c9a43499 100644 --- a/src/docs/guide/usage/linter/rules/promise/no-return-in-finally.md +++ b/src/docs/guide/usage/linter/rules/promise/no-return-in-finally.md @@ -14,7 +14,9 @@ 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) { @@ -22,6 +24,14 @@ myPromise.finally(function (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) diff --git a/src/docs/guide/usage/linter/rules/promise/param-names.md b/src/docs/guide/usage/linter/rules/promise/param-names.md index 978b20b412c..82a19fcc75f 100644 --- a/src/docs/guide/usage/linter/rules/promise/param-names.md +++ b/src/docs/guide/usage/linter/rules/promise/param-names.md @@ -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) { @@ -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) diff --git a/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md b/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md index abb485c690a..e30a260a5c8 100644 --- a/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md +++ b/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md @@ -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 diff --git a/src/docs/guide/usage/linter/rules/promise/valid-params.md b/src/docs/guide/usage/linter/rules/promise/valid-params.md index 8b5b943e206..9a049c792c9 100644 --- a/src/docs/guide/usage/linter/rules/promise/valid-params.md +++ b/src/docs/guide/usage/linter/rules/promise/valid-params.md @@ -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)