Skip to content

Commit 905f3a3

Browse files
JoshuaKGoldbergauvred
authored andcommitted
docs(eslint-plugin): enforce a heading for each rule option (typescript-eslint#8015)
* docs(eslint-plugin): enforce a heading for each rule option * Fix lint
1 parent 657d53c commit 905f3a3

14 files changed

+332
-46
lines changed

Diff for: .cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"declarators",
7373
"destructure",
7474
"destructured",
75+
"destructures",
7576
"discoverability",
7677
"dprint",
7778
"errored",

Diff for: packages/eslint-plugin/docs/rules/explicit-member-accessibility.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class Animal {
164164
}
165165
```
166166

167-
### Overrides
167+
### `overrides`
168168

169169
There are three ways in which an override can be used.
170170

@@ -312,7 +312,7 @@ class Animal {
312312
}
313313
```
314314

315-
### Except specific methods
315+
### `ignoredMethodNames`
316316

317317
If you want to ignore some specific methods, you can do it by specifying method names. Note that this option does not care for the context, and will ignore every method with these names, which could lead to it missing some cases. You should use this sparingly.
318318
e.g. `[ { ignoredMethodNames: ['specificMethod', 'whateverMethod'] } ]`

Diff for: packages/eslint-plugin/docs/rules/no-empty-interface.md

+2-13
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,9 @@ interface Baz extends Foo, Bar {}
5050

5151
## Options
5252

53-
This rule accepts a single object option with the following default configuration:
54-
55-
```json
56-
{
57-
"@typescript-eslint/no-empty-interface": [
58-
"error",
59-
{
60-
"allowSingleExtends": false
61-
}
62-
]
63-
}
64-
```
53+
### `allowSingleExtends`
6554

66-
- `allowSingleExtends: true` will silence warnings about extending a single interface without adding additional members
55+
`allowSingleExtends: true` will silence warnings about extending a single interface without adding additional members
6756

6857
## When Not To Use It
6958

Diff for: packages/eslint-plugin/docs/rules/no-explicit-any.md

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ function greet(param: Array<string>): Array<string> {}
9494

9595
## Options
9696

97+
### `fixToUnknown`
98+
99+
By default, this rule will not provide automatic ESLint _fixes_: only opt-in _suggestions_.
100+
Switching types to `unknown` is safer but is likely to cause additional type errors.
101+
102+
Enabling `{ "fixToUnknown": true }` gives the rule an auto-fixer to replace `: any` with `: unknown`.
103+
97104
### `ignoreRestArgs`
98105

99106
A boolean to specify if arrays from the rest operator are considered okay. `false` by default.

Diff for: packages/eslint-plugin/docs/rules/no-meaningless-void-operator.md

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void bar(); // discarding a number
4444

4545
## Options
4646

47+
### `checkNever`
48+
4749
`checkNever: true` will suggest removing `void` when the argument has type `never`.
4850

4951
## When Not To Use It

Diff for: packages/eslint-plugin/docs/rules/no-misused-promises.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See [`no-floating-promises`](./no-floating-promises.md) for detecting unhandled
1717

1818
## Options
1919

20-
### `"checksConditionals"`
20+
### `checksConditionals`
2121

2222
If you don't want to check conditionals, you can configure the rule with `"checksConditionals": false`:
2323

@@ -73,7 +73,7 @@ while (await promise) {
7373

7474
<!--/tabs-->
7575

76-
### `"checksVoidReturn"`
76+
### `checksVoidReturn`
7777

7878
Likewise, if you don't want to check functions that return promises where a void return is
7979
expected, your configuration will look like this:
@@ -182,7 +182,7 @@ eventEmitter.on('some-event', () => {
182182

183183
<!--/tabs-->
184184

185-
### `"checksSpreads"`
185+
### `checksSpreads`
186186

187187
If you don't want to check object spreads, you can add this configuration:
188188

Diff for: packages/eslint-plugin/docs/rules/no-this-alias.md

+69
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,75 @@ setTimeout(() => {
3333

3434
## Options
3535

36+
### `allowDestructuring`
37+
38+
It can sometimes be useful to destructure properties from a class instance, such as retrieving multiple properties from the instance in one of its methods.
39+
`allowDestructuring` allows those destructures and is `true` by default.
40+
You can explicitly disallow them by setting `allowDestructuring` to `false`.
41+
42+
Examples of code for the `{ "allowDestructuring": false }` option:
43+
44+
<!--tabs-->
45+
46+
#### ❌ Incorrect
47+
48+
```ts option='{ "allowDestructuring": false }'
49+
class ComponentLike {
50+
props: unknown;
51+
state: unknown;
52+
53+
render() {
54+
const { props, state } = this;
55+
56+
console.log(props);
57+
console.log(state);
58+
}
59+
}
60+
```
61+
62+
#### ✅ Correct
63+
64+
```ts option='{ "allowDestructuring": false }'
65+
class ComponentLike {
66+
props: unknown;
67+
state: unknown;
68+
69+
render() {
70+
console.log(this.props);
71+
console.log(this.state);
72+
}
73+
}
74+
```
75+
76+
### `allowedNames`
77+
78+
`no-this-alias` can alternately be used to allow only a specific list of names as `this` aliases.
79+
We recommend against this except as a transitory step towards fixing all rule violations.
80+
81+
Examples of code for the `{ "allowedNames": ["self"] }` option:
82+
83+
<!--tabs-->
84+
85+
#### ❌ Incorrect
86+
87+
```ts option='{ "allowedNames": ["self"] }'
88+
class Example {
89+
method() {
90+
const that = this;
91+
}
92+
}
93+
```
94+
95+
#### ✅ Correct
96+
97+
```ts option='{ "allowedNames": ["self"] }'
98+
class Example {
99+
method() {
100+
const self = this;
101+
}
102+
}
103+
```
104+
36105
## When Not To Use It
37106

38107
If your project is structured in a way that it needs to assign `this` to variables, this rule is likely not for you.

Diff for: packages/eslint-plugin/docs/rules/parameter-properties.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It may take an options object containing either or both of:
1919
- `"allow"`: allowing certain kinds of properties to be ignored
2020
- `"prefer"`: either `"class-property"` _(default)_ or `"parameter-property"`
2121

22-
### `"allow"`
22+
### `allow`
2323

2424
If you would like to ignore certain kinds of properties then you may pass an object containing `"allow"` as an array of any of the following options:
2525

@@ -45,7 +45,7 @@ For example, to ignore `public` properties:
4545
}
4646
```
4747

48-
### `"prefer"`
48+
### `prefer`
4949

5050
By default, the rule prefers class property (`"class-property"`).
5151
You can switch it to instead preferring parameter property with (`"parameter-property"`).

Diff for: packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ enum Valid {
6161

6262
## Options
6363

64-
- `allowBitwiseExpressions` set to `true` will allow you to use bitwise expressions in enum initializer (Default: `false`).
64+
### `allowBitwiseExpressions`
65+
66+
When set to `true` will allow you to use bitwise expressions in enum initializer (default: `false`).
6567

6668
Examples of code for the `{ "allowBitwiseExpressions": true }` option:
6769

Diff for: packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md

+10
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ foo ?? 'a string';
167167

168168
Also, if you would like to ignore all primitives types, you can set `ignorePrimitives: true`. It is equivalent to `ignorePrimitives: { string: true, number: true, bigint: true, boolean: true }`.
169169

170+
### `allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing`
171+
172+
If this is set to `false`, then the rule will error on every file whose `tsconfig.json` does _not_ have the `strictNullChecks` compiler option (or `strict`) set to `true`.
173+
174+
Without `strictNullChecks`, TypeScript essentially erases `undefined` and `null` from the types. This means when this rule inspects the types from a variable, **it will not be able to tell that the variable might be `null` or `undefined`**, which essentially makes this rule useless.
175+
176+
You should be using `strictNullChecks` to ensure complete type-safety in your codebase.
177+
178+
If for some reason you cannot turn on `strictNullChecks`, but still want to use this rule - you can use this option to allow it - but know that the behavior of this rule is _undefined_ with the compiler option turned off. We will not accept bug reports if you are using this option.
179+
170180
## When Not To Use It
171181

172182
If you are not using TypeScript 3.7 (or greater), then you will not be able to use this rule, as the operator is not supported.

Diff for: packages/eslint-plugin/docs/rules/promise-function-async.md

+68
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,74 @@ async function functionReturnsUnionWithPromiseImplicitly(p: boolean) {
5858
}
5959
```
6060

61+
## Options
62+
63+
### `allowAny`
64+
65+
Whether to ignore functions that return `any` and `unknown`.
66+
If you want additional safety, consider turning this option off, as it makes the rule less able to catch incorrect Promise behaviors.
67+
68+
Examples of code with `{ "allowAny": false }`:
69+
70+
<!--tabs-->
71+
72+
#### ❌ Incorrect
73+
74+
```ts option='{ "allowAny": false }'
75+
const returnsAny = () => ({}) as any;
76+
```
77+
78+
#### ✅ Correct
79+
80+
```ts option='{ "allowAny": false }'
81+
const returnsAny = async () => ({}) as any;
82+
```
83+
84+
### `allowedPromiseNames`
85+
86+
For projects that use constructs other than the global built-in `Promise` for asynchronous code.
87+
This option allows specifying string names of classes or interfaces that cause a function to be checked as well.
88+
89+
Examples of code with `{ "allowedPromiseNames": ["Bluebird"] }`:
90+
91+
<!--tabs-->
92+
93+
#### ❌ Incorrect
94+
95+
```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
96+
import { Bluebird } from 'bluebird';
97+
98+
const returnsBluebird = () => new Bluebird(() => {});
99+
```
100+
101+
#### ✅ Correct
102+
103+
```ts option='{ "allowedPromiseNames": ["Bluebird"] }'
104+
import { Bluebird } from 'bluebird';
105+
106+
const returnsBluebird = async () => new Bluebird(() => {});
107+
```
108+
109+
### `checkArrowFunctions`
110+
111+
Whether to check arrow functions.
112+
`true` by default, but can be set to `false` to ignore them.
113+
114+
### `checkFunctionDeclarations`
115+
116+
Whether to check standalone function declarations.
117+
`true` by default, but can be set to `false` to ignore them.
118+
119+
### `checkFunctionExpressions`
120+
121+
Whether to check inline function expressions.
122+
`true` by default, but can be set to `false` to ignore them.
123+
124+
### `checkMethodDeclarations`
125+
126+
Whether to check methods on classes and object literals
127+
`true` by default, but can be set to `false` to ignore them.
128+
61129
## When Not To Use It
62130

63131
This rule can be difficult to enable on projects that use APIs which require functions to always be `async`.

Diff for: packages/eslint-plugin/docs/rules/sort-type-constituents.md

+56
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,46 @@ type T4 =
8282

8383
## Options
8484

85+
### `checkIntersections`
86+
87+
Whether to check intersection types (`&`).
88+
89+
Examples of code with `{ "checkIntersections": true }` (the default):
90+
91+
<!--tabs-->
92+
93+
#### ❌ Incorrect
94+
95+
```ts option='{ "checkIntersections": true }'
96+
type ExampleIntersection = B & A;
97+
```
98+
99+
#### ✅ Correct
100+
101+
```ts option='{ "checkIntersections": true }'
102+
type ExampleIntersection = A & B;
103+
```
104+
105+
### `checkUnions`
106+
107+
Whether to check union types (`|`).
108+
109+
Examples of code with `{ "checkUnions": true }` (the default):
110+
111+
<!--tabs-->
112+
113+
#### ❌ Incorrect
114+
115+
```ts option='{ "checkUnions": true }'
116+
type ExampleUnion = B | A;
117+
```
118+
119+
#### ✅ Correct
120+
121+
```ts option='{ "checkUnions": true }'
122+
type ExampleUnion = A | B;
123+
```
124+
85125
### `groupOrder`
86126

87127
Each constituent of the type is placed into a group, and then the rule sorts alphabetically within each group.
@@ -100,6 +140,22 @@ The ordering of groups is determined by this option.
100140
- `union` - Union types (`A | B`)
101141
- `nullish` - `null` and `undefined`
102142

143+
For example, configuring the rule with `{ "groupOrder": ["literal", "nullish" ]}`:
144+
145+
<!--tabs-->
146+
147+
#### ❌ Incorrect
148+
149+
```ts option='{ "groupOrder": ["literal", "nullish" ]}'
150+
type ExampleGroup = null | 123;
151+
```
152+
153+
#### ✅ Correct
154+
155+
```ts option='{ "groupOrder": ["literal", "nullish" ]}'
156+
type ExampleGroup = 123 | null;
157+
```
158+
103159
## When Not To Use It
104160

105161
This rule is purely a stylistic rule for maintaining consistency in your project.

0 commit comments

Comments
 (0)