Skip to content

Commit c7ec887

Browse files
docs: fix docs for no-promise-reject
1 parent 675fa1e commit c7ec887

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

docs/rules/no-promise-reject.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
# Disallow try-catch[-finally] and try-finally patterns (`functional/no-promise-reject`)
1+
# Disallow rejecting promises
22

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

55
This rule disallows use of `Promise.reject()`.
66

7-
We don't recommend this rule but it's there for those who want it.
8-
97
## Rule Details
108

11-
You can view a `Promise` as a result object with built-in error (something like `{ value: T } | { error: Error }`) in which case a rejected `Promise` can be viewed as a returned result and thus fits with functional programming.
12-
You can also view a rejected promise as something similar to an exception and as such something that does not fit with functional programming.
13-
If your view is the latter you can use the `no-promise-reject` rule to disallow rejected promises.
9+
It is useful when using an `Option` type (something like `{ value: T } | { error: Error }`)
10+
for handling errors. In this case a promise should always resolve with an `Option` and never reject.
11+
12+
This rule should be used in conjunction with [`no-throw-statements`](./no-throw-statements.md).
1413

1514
### ❌ Incorrect
1615

@@ -36,6 +35,8 @@ async function divide(x, y) {
3635
async function divide(x, y) {
3736
const [xv, yv] = await Promise.all([x, y]);
3837

39-
return yv === 0 ? new Error("Cannot divide by zero.") : xv / yv;
38+
return yv === 0
39+
? { error: new Error("Cannot divide by zero.") }
40+
: { value: xv / yv};
4041
}
4142
```

src/rules/no-promise-reject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const meta: NamedCreateRuleMetaWithCategory<keyof typeof errorMessages> = {
4646
type: "suggestion",
4747
docs: {
4848
category: "No Exceptions",
49-
description: "Disallow try-catch[-finally] and try-finally patterns.",
49+
description: "Disallow rejecting promises.",
5050
},
5151
messages: errorMessages,
5252
schema,

0 commit comments

Comments
 (0)