mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
docs(linter): improve docs for promise rules (#6051)
This commit is contained in:
parent
b1af73db81
commit
a4fdf1bc49
7 changed files with 36 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue