Skip to content

Commit 36d13f5

Browse files
authored
docs: add for prefer-await-to-callbacks; fixes #118 (#491)
1 parent c011a1a commit 36d13f5

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ or start with the recommended rule set:
112112
| [no-return-in-finally](docs/rules/no-return-in-finally.md) | Disallow return statements in `finally()`. | || | |
113113
| [no-return-wrap](docs/rules/no-return-wrap.md) | Disallow wrapping values in `Promise.resolve` or `Promise.reject` when not needed. || | | |
114114
| [param-names](docs/rules/param-names.md) | Enforce consistent param names and ordering when creating new promises. || | | |
115-
| [prefer-await-to-callbacks](docs/rules/prefer-await-to-callbacks.md) | Prefer async/await to the callback pattern. | | | | |
115+
| [prefer-await-to-callbacks](docs/rules/prefer-await-to-callbacks.md) | Prefer `async`/`await` to the callback pattern. | | | | |
116116
| [prefer-await-to-then](docs/rules/prefer-await-to-then.md) | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values. | | | | |
117117
| [valid-params](docs/rules/valid-params.md) | Enforces the proper number of arguments are passed to Promise functions. | || | |
118118

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1-
# Prefer async/await to the callback pattern (`promise/prefer-await-to-callbacks`)
1+
# Prefer `async`/`await` to the callback pattern (`promise/prefer-await-to-callbacks`)
22

33
<!-- end auto-generated rule header -->
4+
5+
`async`/`await` is a clearer pattern to follow than using callbacks.
6+
7+
## Rule details
8+
9+
ES2017's `async`/`await` makes it easier to deal with asynchronous code than the
10+
callback pattern.
11+
12+
Examples of **incorrect** code for this rule:
13+
14+
```js
15+
cb()
16+
callback()
17+
doSomething(arg, (err) => {})
18+
function doSomethingElse(cb) {}
19+
```
20+
21+
Examples of **correct** code for this rule:
22+
23+
```js
24+
await doSomething(arg)
25+
async function doSomethingElse() {}
26+
yield yieldValue(err => {})
27+
eventEmitter.on('error', err => {})
28+
```
29+
30+
## When Not To Use It
31+
32+
If you are not targeting an ES2017 or higher environment and cannot transpile
33+
`async`/`await`, you should disable this rule.
34+
35+
## Further Reading
36+
37+
- [Making asynchronous programming easier with async and await on MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises)

rules/prefer-await-to-callbacks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
meta: {
88
type: 'suggestion',
99
docs: {
10-
description: 'Prefer async/await to the callback pattern.',
10+
description: 'Prefer `async`/`await` to the callback pattern.',
1111
url: getDocsUrl('prefer-await-to-callbacks'),
1212
},
1313
messages: {

0 commit comments

Comments
 (0)