File tree 3 files changed +37
-3
lines changed
3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ or start with the recommended rule set:
112
112
| [ no-return-in-finally] ( docs/rules/no-return-in-finally.md ) | Disallow return statements in ` finally() ` . | | ✅ | | |
113
113
| [ no-return-wrap] ( docs/rules/no-return-wrap.md ) | Disallow wrapping values in ` Promise.resolve ` or ` Promise.reject ` when not needed. | ✅ | | | |
114
114
| [ 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. | | | | |
116
116
| [ prefer-await-to-then] ( docs/rules/prefer-await-to-then.md ) | Prefer ` await ` to ` then() ` /` catch() ` /` finally() ` for reading Promise values. | | | | |
117
117
| [ valid-params] ( docs/rules/valid-params.md ) | Enforces the proper number of arguments are passed to Promise functions. | | ✅ | | |
118
118
Original file line number Diff line number Diff line change 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 ` )
2
2
3
3
<!-- 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 )
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module.exports = {
7
7
meta : {
8
8
type : 'suggestion' ,
9
9
docs : {
10
- description : 'Prefer async/ await to the callback pattern.' ,
10
+ description : 'Prefer ` async`/` await` to the callback pattern.' ,
11
11
url : getDocsUrl ( 'prefer-await-to-callbacks' ) ,
12
12
} ,
13
13
messages : {
You can’t perform that action at this time.
0 commit comments