Skip to content

Commit

Permalink
feat(no-throw-statements)!: replace option allowInAsyncFunctions wi…
Browse files Browse the repository at this point in the history
…th `allowToRejectPromises`
  • Loading branch information
RebeccaStevens committed Jul 5, 2024
1 parent 23b1c44 commit 9414dcf
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 152 deletions.
12 changes: 6 additions & 6 deletions docs/rules/no-throw-statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ This rule accepts an options object of the following type:

```ts
type Options = {
allowInAsyncFunctions: boolean;
allowToRejectPromises: boolean;
};
```

### Default Options

```ts
const defaults = {
allowInAsyncFunctions: false,
allowToRejectPromises: false,
};
```

Expand All @@ -72,19 +72,19 @@ const defaults = {

```ts
const recommendedAndLiteOptions = {
allowInAsyncFunctions: true,
allowToRejectPromises: true,
};
```

### `allowInAsyncFunctions`
### `allowToRejectPromises`

If true, throw statements will be allowed within async functions.\
If true, throw statements will be allowed when they are used to reject a promise, such when in an async function.\
This essentially allows throw statements to be used as return statements for errors.

#### ✅ Correct

```js
/* eslint functional/no-throw-statements: ["error", { "allowInAsyncFunctions": true }] */
/* eslint functional/no-throw-statements: ["error", { "allowToRejectPromises": true }] */

async function divide(x, y) {
const [xv, yv] = await Promise.all([x, y]);
Expand Down
Loading

0 comments on commit 9414dcf

Please sign in to comment.