Skip to content

Commit cfd5506

Browse files
authored
docs: automate docs with eslint-doc-generator (#396)
1 parent 23bf271 commit cfd5506

34 files changed

+1907
-246
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"prefer-arrow-callback": "error",
2020
"prefer-const": "error",
2121
"strict": ["error", "global"],
22+
"eslint-plugin/require-meta-docs-description": ["error", { "pattern": "^(Enforce|Require|Disallow|Prefer).+\\.$" }],
2223
"eslint-plugin/prefer-placeholders": "error",
2324
"eslint-plugin/test-case-shorthand-strings": "error",
2425
"node/no-unsupported-features": ["error", { "version": 6 }],

README.md

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Enforce best practices for JavaScript promises.
2121

2222
You'll first need to install [ESLint](http://eslint.org):
2323

24-
```
25-
$ npm install eslint --save-dev
24+
```sh
25+
npm install eslint --save-dev
2626
```
2727

2828
Next, install `eslint-plugin-promise`:
2929

30-
```
31-
$ npm install eslint-plugin-promise --save-dev
30+
```sh
31+
npm install eslint-plugin-promise --save-dev
3232
```
3333

3434
**Note:** If you installed ESLint globally (using the `-g` flag) then you must
@@ -76,32 +76,30 @@ or start with the recommended rule set:
7676

7777
## Rules
7878

79-
| rule | description | recommended | fixable |
80-
| -------------------------------------------------------- | -------------------------------------------------------------------------------- | ----------- | -------- |
81-
| [`catch-or-return`][catch-or-return] | Enforces the use of `catch()` on un-returned promises. | :bangbang: | |
82-
| [`no-return-wrap`][no-return-wrap] | Avoid wrapping values in `Promise.resolve` or `Promise.reject` when not needed. | :bangbang: | |
83-
| [`param-names`][param-names] | Enforce consistent param names and ordering when creating new promises. | :bangbang: | |
84-
| [`always-return`][always-return] | Return inside each `then()` to create readable and reusable Promise chains. | :bangbang: | |
85-
| [`no-native`][no-native] | In an ES5 environment, make sure to create a `Promise` constructor before using. | | |
86-
| [`no-nesting`][no-nesting] | Avoid nested `then()` or `catch()` statements | :warning: | |
87-
| [`no-promise-in-callback`][no-promise-in-callback] | Avoid using promises inside of callbacks | :warning: | |
88-
| [`no-callback-in-promise`][no-callback-in-promise] | Avoid calling `cb()` inside of a `then()` (use [nodeify][] instead) | :warning: | |
89-
| [`avoid-new`][avoid-new] | Avoid creating `new` promises outside of utility libs (use [pify][] instead) | | |
90-
| [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | :wrench: |
91-
| [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | |
92-
| [`valid-params`][valid-params] | Ensures the proper number of arguments are passed to Promise functions | :warning: | |
93-
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values | :seven: | |
94-
| [`prefer-await-to-callbacks`][prefer-await-to-callbacks] | Prefer async/await to the callback pattern | :seven: | |
95-
| [`no-multiple-resolved`][no-multiple-resolved] | Disallow creating new promises with paths that resolve multiple times | | |
96-
97-
**Key**
98-
99-
| icon | description |
100-
| ---------- | ----------------------------------------------- |
101-
| :bangbang: | Reports as error in recommended configuration |
102-
| :warning: | Reports as warning in recommended configuration |
103-
| :seven: | ES2017 Async Await rules |
104-
| :wrench: | Rule is fixable with `eslint --fix` |
79+
<!-- begin auto-generated rules list -->
80+
81+
✅ Enabled in the `recommended` configuration.\
82+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
83+
84+
| Name                      | Description || 🔧 |
85+
| :------------------------------------------------------------------- | :------------------------------------------------------------------------------------- | :- | :- |
86+
| [always-return](docs/rules/always-return.md) | Require returning inside each `then()` to create readable and reusable Promise chains. || |
87+
| [avoid-new](docs/rules/avoid-new.md) | Disallow creating `new` promises outside of utility libs (use [pify][] instead). | | |
88+
| [catch-or-return](docs/rules/catch-or-return.md) | Enforce the use of `catch()` on un-returned promises. || |
89+
| [no-callback-in-promise](docs/rules/no-callback-in-promise.md) | Disallow calling `cb()` inside of a `then()` (use [nodeify][] instead). | | |
90+
| [no-multiple-resolved](docs/rules/no-multiple-resolved.md) | Disallow creating new promises with paths that resolve multiple times. | | |
91+
| [no-native](docs/rules/no-native.md) | Require creating a `Promise` constructor before using it in an ES5 environment. | | |
92+
| [no-nesting](docs/rules/no-nesting.md) | Disallow nested `then()` or `catch()` statements. | | |
93+
| [no-new-statics](docs/rules/no-new-statics.md) | Disallow calling `new` on a Promise static method. || 🔧 |
94+
| [no-promise-in-callback](docs/rules/no-promise-in-callback.md) | Disallow using promises inside of callbacks. | | |
95+
| [no-return-in-finally](docs/rules/no-return-in-finally.md) | Disallow return statements in `finally()`. | | |
96+
| [no-return-wrap](docs/rules/no-return-wrap.md) | Disallow wrapping values in `Promise.resolve` or `Promise.reject` when not needed. || |
97+
| [param-names](docs/rules/param-names.md) | Enforce consistent param names and ordering when creating new promises. || |
98+
| [prefer-await-to-callbacks](docs/rules/prefer-await-to-callbacks.md) | Prefer async/await to the callback pattern. | | |
99+
| [prefer-await-to-then](docs/rules/prefer-await-to-then.md) | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values. | | |
100+
| [valid-params](docs/rules/valid-params.md) | Enforces the proper number of arguments are passed to Promise functions. | | |
101+
102+
<!-- end auto-generated rules list -->
105103

106104
## Maintainers
107105

@@ -114,21 +112,6 @@ or start with the recommended rule set:
114112
- (c) MMXV jden <mailto:[email protected]> - ISC license.
115113
- (c) 2016 Jamund Ferguson <mailto:[email protected]> - ISC license.
116114

117-
[catch-or-return]: docs/rules/catch-or-return.md
118-
[no-return-wrap]: docs/rules/no-return-wrap.md
119-
[param-names]: docs/rules/param-names.md
120-
[always-return]: docs/rules/always-return.md
121-
[no-native]: docs/rules/no-native.md
122-
[no-nesting]: docs/rules/no-nesting.md
123-
[no-promise-in-callback]: docs/rules/no-promise-in-callback.md
124-
[no-callback-in-promise]: docs/rules/no-callback-in-promise.md
125-
[avoid-new]: docs/rules/avoid-new.md
126-
[no-new-statics]: docs/rules/no-new-statics.md
127-
[no-return-in-finally]: docs/rules/no-return-in-finally.md
128-
[valid-params]: docs/rules/valid-params.md
129-
[prefer-await-to-then]: docs/rules/prefer-await-to-then.md
130-
[prefer-await-to-callbacks]: docs/rules/prefer-await-to-callbacks.md
131-
[no-multiple-resolved]: docs/rules/no-multiple-resolved.md
132115
[nodeify]: https://www.npmjs.com/package/nodeify
133116
[pify]: https://www.npmjs.com/package/pify
134117
[@aaditmshah]: https://github.com/aaditmshah

docs/rules/always-return.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Return inside each `then()` to create readable and reusable Promise chains (always-return)
1+
# Require returning inside each `then()` to create readable and reusable Promise chains (`promise/always-return`)
2+
3+
✅ This rule is enabled in the `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
26

37
Ensure that inside a `then()` you make sure to `return` a new promise or value.
48
See http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html (rule #5)

docs/rules/avoid-new.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
# Avoid creating `new` promises outside of utility libs (use [pify][] instead) (avoid-new)
1+
# Disallow creating `new` promises outside of utility libs (use [pify][] instead) (`promise/avoid-new`)
2+
3+
✅ This rule is _disabled_ in the `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
26

37
[pify]: https://www.npmjs.com/package/pify

docs/rules/catch-or-return.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Enforces the use of `catch()` on un-returned promises (catch-or-return)
1+
# Enforce the use of `catch()` on un-returned promises (`promise/catch-or-return`)
2+
3+
✅ This rule is enabled in the `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
26

37
Ensure that each time a `then()` is applied to a promise, a `catch()` is applied
48
as well. Exceptions are made if you are returning that promise.

docs/rules/no-callback-in-promise.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Avoid calling `cb()` inside of a `then()` or `catch()` (no-callback-in-promise)
1+
# Disallow calling `cb()` inside of a `then()` (use [nodeify][] instead) (`promise/no-callback-in-promise`)
2+
3+
✅ This rule will _warn_ in the `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
26

37
As a general rule, callbacks should never be directly invoked inside a
48
[Promise.prototype.then()] or [Promise.prototype.catch()] method. That's because
@@ -68,3 +72,11 @@ callback code instead of combining the approaches.
6872
https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_nexttick_callback_args
6973
[settimeout()]:
7074
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
75+
76+
## Options
77+
78+
### `exceptions`
79+
80+
String list of callback function names to exempt.
81+
82+
[nodeify]: https://www.npmjs.com/package/nodeify

docs/rules/no-multiple-resolved.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Disallow creating new promises with paths that resolve multiple times (no-multiple-resolved)
1+
# Disallow creating new promises with paths that resolve multiple times (`promise/no-multiple-resolved`)
2+
3+
<!-- end auto-generated rule header -->
24

35
This rule warns of paths that resolve multiple times in executor functions that
46
Promise constructors.

docs/rules/no-native.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# In an ES5 environment, make sure to create a `Promise` constructor before using (no-native)
1+
# Require creating a `Promise` constructor before using it in an ES5 environment (`promise/no-native`)
2+
3+
✅ This rule is _disabled_ in the `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
26

37
Ensure that `Promise` is included fresh in each file instead of relying on the
48
existence of a native promise implementation. Helpful if you want to use

docs/rules/no-nesting.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Avoid nested `then()` or `catch()` statements (no-nesting)
1+
# Disallow nested `then()` or `catch()` statements (`promise/no-nesting`)
2+
3+
✅ This rule will _warn_ in the `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
26

37
#### Valid
48

docs/rules/no-new-statics.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Avoid calling `new` on a Promise static method (no-new-statics)
1+
# Disallow calling `new` on a Promise static method (`promise/no-new-statics`)
2+
3+
✅ This rule is enabled in the `recommended` config.
4+
5+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6+
7+
<!-- end auto-generated rule header -->
28

39
Calling a Promise static method with `new` is invalid, resulting in a
410
`TypeError` at runtime.
511

6-
:wrench: The `--fix` option on the command line can automatically fix the
7-
problems reported by this rule.
8-
912
## Rule Details
1013

1114
This rule is aimed at flagging instances where a Promise static method is called

0 commit comments

Comments
 (0)