Skip to content

Commit 2673044

Browse files
authored
docs(eslint-plugin): [prefer-promise-reject-errors] add option sections and examples (#12896)
1 parent 38ceff0 commit 2673044

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

‎packages/eslint-plugin/docs/rules/prefer-promise-reject-errors.mdx‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,50 @@ const defaultOptions: Options = {
9898
allowThrowingUnknown: false,
9999
};
100100
```
101+
102+
### `allow`
103+
104+
{/* insert option description */}
105+
106+
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
107+
It can be useful for rejecting with error types defined by libraries that do not extend `Error`.
108+
109+
Examples of code for this rule with:
110+
111+
```jsonc
112+
{
113+
"allow": [{ "from": "file", "name": "CustomError" }],
114+
}
115+
```
116+
117+
```ts option='{ "allow": [{ "from": "file", "name": "CustomError" }] }' showPlaygroundButton
118+
class CustomError /* does NOT extend Error */ {
119+
// ...
120+
}
121+
122+
Promise.reject(new CustomError());
123+
```
124+
125+
### `allowThrowingAny`
126+
127+
{/* insert option description */}
128+
129+
Examples of **correct** code with `{ allowThrowingAny: true }`:
130+
131+
```ts option='{ "allowThrowingAny": true }' showPlaygroundButton
132+
declare const value: any;
133+
134+
Promise.reject(value);
135+
```
136+
137+
### `allowThrowingUnknown`
138+
139+
{/* insert option description */}
140+
141+
Examples of **correct** code with `{ allowThrowingUnknown: true }`:
142+
143+
```ts option='{ "allowThrowingUnknown": true }' showPlaygroundButton
144+
declare const value: unknown;
145+
146+
Promise.reject(value);
147+
```

‎packages/eslint-plugin/tests/docs-eslint-output-snapshots/prefer-promise-reject-errors.shot‎

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)