Skip to content

Commit

Permalink
docs: recommend util.promisify instead of pify and `util.callbackif…
Browse files Browse the repository at this point in the history
…y` over nodeify (#492)
  • Loading branch information
brettz9 authored Jul 22, 2024
1 parent fa482cc commit 9d0e447
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ or start with the recommended rule set:
Set in the `recommended` configuration.\
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).

| Name                      | Description | 💼 | ⚠️ | 🚫 | 🔧 |
| :------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | :-- | :-- | :-- | :-- |
| [always-return](docs/rules/always-return.md) | Require returning inside each `then()` to create readable and reusable Promise chains. || | | |
| [avoid-new](docs/rules/avoid-new.md) | Disallow creating `new` promises outside of utility libs (use [pify][] instead). | | || |
| [catch-or-return](docs/rules/catch-or-return.md) | Enforce the use of `catch()` on un-returned promises. || | | |
| [no-callback-in-promise](docs/rules/no-callback-in-promise.md) | Disallow calling `cb()` inside of a `then()` (use [nodeify][] instead). | || | |
| [no-multiple-resolved](docs/rules/no-multiple-resolved.md) | Disallow creating new promises with paths that resolve multiple times. | | | | |
| [no-native](docs/rules/no-native.md) | Require creating a `Promise` constructor before using it in an ES5 environment. | | | ✅ | |
| [no-nesting](docs/rules/no-nesting.md) | Disallow nested `then()` or `catch()` statements. | | ✅ | | |
| [no-new-statics](docs/rules/no-new-statics.md) | Disallow calling `new` on a Promise static method. | ✅ | | | 🔧 |
| [no-promise-in-callback](docs/rules/no-promise-in-callback.md) | Disallow using promises inside of callbacks. | | ✅ | | |
| [no-return-in-finally](docs/rules/no-return-in-finally.md) | Disallow return statements in `finally()`. | | ✅ | | |
| [no-return-wrap](docs/rules/no-return-wrap.md) | Disallow wrapping values in `Promise.resolve` or `Promise.reject` when not needed. | ✅ | | | |
| [param-names](docs/rules/param-names.md) | Enforce consistent param names and ordering when creating new promises. | ✅ | | | |
| [prefer-await-to-callbacks](docs/rules/prefer-await-to-callbacks.md) | Prefer `async`/`await` to the callback pattern. | | | | |
| [prefer-await-to-then](docs/rules/prefer-await-to-then.md) | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values. | | | | |
| [valid-params](docs/rules/valid-params.md) | Enforces the proper number of arguments are passed to Promise functions. | | ✅ | | |
| Name                      | Description | 💼 | ⚠️ | 🚫 | 🔧 |
| :------------------------------------------------------------------- | :----------------------------------------------------------------------------------------- | :-- | :-- | :-- | :-- |
| [always-return](docs/rules/always-return.md) | Require returning inside each `then()` to create readable and reusable Promise chains. || | | |
| [avoid-new](docs/rules/avoid-new.md) | Disallow creating `new` promises outside of utility libs (use [util.promisify][] instead). | | || |
| [catch-or-return](docs/rules/catch-or-return.md) | Enforce the use of `catch()` on un-returned promises. || | | |
| [no-callback-in-promise](docs/rules/no-callback-in-promise.md) | Disallow calling `cb()` inside of a `then()` (use [util.callbackify][] instead). | || | |
| [no-multiple-resolved](docs/rules/no-multiple-resolved.md) | Disallow creating new promises with paths that resolve multiple times. | | | | |
| [no-native](docs/rules/no-native.md) | Require creating a `Promise` constructor before using it in an ES5 environment. | | | ✅ | |
| [no-nesting](docs/rules/no-nesting.md) | Disallow nested `then()` or `catch()` statements. | | ✅ | | |
| [no-new-statics](docs/rules/no-new-statics.md) | Disallow calling `new` on a Promise static method. | ✅ | | | 🔧 |
| [no-promise-in-callback](docs/rules/no-promise-in-callback.md) | Disallow using promises inside of callbacks. | | ✅ | | |
| [no-return-in-finally](docs/rules/no-return-in-finally.md) | Disallow return statements in `finally()`. | | ✅ | | |
| [no-return-wrap](docs/rules/no-return-wrap.md) | Disallow wrapping values in `Promise.resolve` or `Promise.reject` when not needed. | ✅ | | | |
| [param-names](docs/rules/param-names.md) | Enforce consistent param names and ordering when creating new promises. | ✅ | | | |
| [prefer-await-to-callbacks](docs/rules/prefer-await-to-callbacks.md) | Prefer `async`/`await` to the callback pattern. | | | | |
| [prefer-await-to-then](docs/rules/prefer-await-to-then.md) | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values. | | | | |
| [valid-params](docs/rules/valid-params.md) | Enforces the proper number of arguments are passed to Promise functions. | | ✅ | | |

<!-- end auto-generated rules list -->

Expand All @@ -129,8 +129,10 @@ or start with the recommended rule set:
- (c) MMXV jden <mailto:[email protected]> - ISC license.
- (c) 2016 Jamund Ferguson <mailto:[email protected]> - ISC license.

[nodeify]: https://www.npmjs.com/package/nodeify
[pify]: https://www.npmjs.com/package/pify
[util.callbackify]:
https://nodejs.org/docs/latest/api/util.html#utilcallbackifyoriginal
[util.promisify]:
https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original
[@aaditmshah]: https://github.com/aaditmshah
[@macklinu]: https://github.com/macklinu
[@xjamundx]: https://github.com/xjamundx
5 changes: 3 additions & 2 deletions docs/rules/avoid-new.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Disallow creating `new` promises outside of utility libs (use [pify][] instead) (`promise/avoid-new`)
# Disallow creating `new` promises outside of utility libs (use [util.promisify][] instead) (`promise/avoid-new`)

🚫 This rule is _disabled_ in the following configs: ✅ `flat/recommended`, ✅
`recommended`.

<!-- end auto-generated rule header -->

[pify]: https://www.npmjs.com/package/pify
[util.promisify]:
https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original
5 changes: 3 additions & 2 deletions docs/rules/no-callback-in-promise.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disallow calling `cb()` inside of a `then()` (use [nodeify][] instead) (`promise/no-callback-in-promise`)
# Disallow calling `cb()` inside of a `then()` (use [util.callbackify][] instead) (`promise/no-callback-in-promise`)

⚠️ This rule _warns_ in the following configs: ✅ `flat/recommended`, ✅
`recommended`.
Expand Down Expand Up @@ -80,4 +80,5 @@ callback code instead of combining the approaches.

String list of callback function names to exempt.

[nodeify]: https://www.npmjs.com/package/nodeify
[util.callbackify]:
https://nodejs.org/docs/latest/api/util.html#utilcallbackifyoriginal
2 changes: 1 addition & 1 deletion rules/avoid-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
type: 'suggestion',
docs: {
description:
'Disallow creating `new` promises outside of utility libs (use [pify][] instead).',
'Disallow creating `new` promises outside of utility libs (use [util.promisify][] instead).',
url: getDocsUrl('avoid-new'),
},
schema: [],
Expand Down
2 changes: 1 addition & 1 deletion rules/no-callback-in-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
type: 'suggestion',
docs: {
description:
'Disallow calling `cb()` inside of a `then()` (use [nodeify][] instead).',
'Disallow calling `cb()` inside of a `then()` (use [util.callbackify][] instead).',
url: getDocsUrl('no-callback-in-promise'),
},
messages: {
Expand Down

0 comments on commit 9d0e447

Please sign in to comment.