docs(linter): improve docs for promise rules (#6051)

This commit is contained in:
dalaoshu 2024-09-25 20:33:07 +08:00 committed by GitHub
parent b1af73db81
commit a4fdf1bc49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 36 additions and 8 deletions

View file

@ -22,7 +22,7 @@ declare_oxc_lint!(
/// 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:
/// ```javascript

View file

@ -60,7 +60,7 @@ declare_oxc_lint!(
/// promise rejections can cause your application to crash.
///
///
/// ### Example
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```javascript

View file

@ -26,7 +26,7 @@ declare_oxc_lint!(
/// 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:
/// ```javascript

View file

@ -28,12 +28,19 @@ declare_oxc_lint!(
/// 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) })
/// ```
NoReturnInFinally,
nursery,
);

View file

@ -50,11 +50,18 @@ declare_oxc_lint!(
/// 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) { /* ... */ }) // incorrect order
/// new Promise(function (ok, fail) { /* ... */ }) // non-standard parameter names
/// ```
///
/// Examples of **correct** code for this rule:
/// ```javascript
/// new Promise(function(resolve, reject) {})
/// ```
ParamNames,
style,
);

View file

@ -21,9 +21,16 @@ declare_oxc_lint!(
///
/// Async/await syntax can be seen as more readable.
///
/// ### Example
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```javascript
/// myPromise.then(doSomething)
/// function foo() { hey.then(x => {}) }
/// ```
///
/// Examples of **correct** code for this rule:
/// ```javascript
/// async function hi() { await thing() }
/// ```
PreferAwaitToThen,
style,

View file

@ -51,10 +51,17 @@ declare_oxc_lint!(
/// 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)
/// ```
ValidParams,
correctness,
);