Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: migrate rule documentation to docs/rules (#112)
Related to #109
- Loading branch information
Showing
15 changed files
with
235 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Return inside each `then()` to create readable and reusable Promise chains (always-return) | ||
|
||
Ensure that inside a `then()` you make sure to `return` a new promise or value. | ||
See http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html (rule #5) | ||
for more info on why that's a good idea. | ||
|
||
We also allow someone to `throw` inside a `then()` which is essentially the same | ||
as `return Promise.reject()`. | ||
|
||
#### Valid | ||
|
||
```js | ||
myPromise.then((val) => val * 2)); | ||
myPromise.then(function(val) { return val * 2; }); | ||
myPromise.then(doSomething); // could be either | ||
myPromise.then((b) => { if (b) { return "yes" } else { return "no" } }); | ||
``` | ||
|
||
#### Invalid | ||
|
||
```js | ||
myPromise.then(function(val) {}) | ||
myPromise.then(() => { | ||
doSomething() | ||
}) | ||
myPromise.then(b => { | ||
if (b) { | ||
return 'yes' | ||
} else { | ||
forgotToReturn() | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Avoid creating `new` promises outside of utility libs (use [pify][] instead) (avoid-new) | ||
|
||
[pify]: https://www.npmjs.com/package/pify |
Oops, something went wrong.