Skip to content

Commit 81f3ffc

Browse files
JoshuaKGoldbergJosh-Cenabradzacher
authored
chore(website): generate rule docs options automatically (#5386)
* chore(website): generate rule docs options automatically * Apply suggestions from code review Co-authored-by: Joshua Chen <[email protected]> * First round of changes * Simplify Prettier types * Progress on using defs * Progress, through the letter 'd' for rules * Through explicit-module-boundary-types * rip, ban-types defaults * Cleaner separation for adding headers * ...I meant headings * Finished specifically base rule extensions * Fix unit test, and enable debug cypress logging * Fix deprecation notices, and ci.yml env indent * Fix up lang and <sup> * No, not sup * Removed bunch more options docs cruft * naming-convention, I give up * Aha, a missing lint rule * member-ordering, I give up on you too * Several more docs automations * Fixed options index * Also above Related To * Aha, jsx working * Thanks lint - correct no-inferrable-types headings * Update packages/eslint-plugin/src/rules/no-implicit-any-catch.ts Co-authored-by: Brad Zacher <[email protected]> * Fix explicit-function-return-type Co-authored-by: Joshua Chen <[email protected]> Co-authored-by: Brad Zacher <[email protected]>
1 parent ff573d9 commit 81f3ffc

File tree

150 files changed

+882
-2259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+882
-2259
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ jobs:
188188
- name: Install Cypress
189189
run: yarn cypress install
190190

191-
- name: Cypress run
191+
- env:
192+
DEBUG: '@cypress/github-action'
193+
name: Cypress run
192194
uses: cypress-io/github-action@v2
193195
with:
194196
project: ./packages/website

packages/eslint-plugin/docs/rules/TEMPLATE.md

-27
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,6 @@ To fill out: tell us more about this rule.
2020
// To fill out: correct code
2121
```
2222

23-
## Options
24-
25-
This rule is not configurable.
26-
27-
```jsonc
28-
// .eslintrc.json
29-
{
30-
"rules": {
31-
"@typescript-eslint/your-rule-name": "error"
32-
}
33-
}
34-
```
35-
36-
If not configurable: This rule is not configurable.
37-
38-
If configurable...
39-
40-
```ts
41-
type Options = {
42-
someOption?: boolean;
43-
};
44-
45-
const defaultOptions: Options = {
46-
someOption: false,
47-
};
48-
```
49-
5023
## When Not To Use It
5124

5225
To fill out: why wouldn't you want to use this rule?

packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md

-13
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ export function foo(n: number): void;
8888
export function foo(sn: string | number): void;
8989
```
9090

91-
## Options
92-
93-
```jsonc
94-
// .eslintrc.json
95-
{
96-
"rules": {
97-
"@typescript-eslint/adjacent-overload-signatures": "error"
98-
}
99-
}
100-
```
101-
102-
This rule is not configurable.
103-
10491
## When Not To Use It
10592

10693
If you don't care about the general structure of the code, then you will not need this rule.

packages/eslint-plugin/docs/rules/array-type.md

-19
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,6 @@ This rule aims to standardize usage of array types within your codebase.
1414

1515
## Options
1616

17-
```ts
18-
type ArrayOption = 'array' | 'generic' | 'array-simple';
19-
type Options = {
20-
default: ArrayOption;
21-
readonly?: ArrayOption;
22-
};
23-
24-
const defaultOptions: Options = {
25-
default: 'array',
26-
};
27-
```
28-
29-
The rule accepts an options object with the following properties:
30-
31-
- `default` - sets the array type expected for mutable cases.
32-
- `readonly` - sets the array type expected for readonly arrays. If this is omitted, then the value for `default` will be used.
33-
34-
Each property can be set to one of three strings: `'array' | 'generic' | 'array-simple'`.
35-
3617
The default config will enforce that all mutable and readonly arrays use the `'array'` syntax.
3718

3819
### `"array"`

packages/eslint-plugin/docs/rules/await-thenable.md

-13
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ const createValue = async () => 'value';
3333
await createValue();
3434
```
3535

36-
## Options
37-
38-
```jsonc
39-
// .eslintrc.json
40-
{
41-
"rules": {
42-
"@typescript-eslint/await-thenable": "error"
43-
}
44-
}
45-
```
46-
47-
This rule is not configurable.
48-
4936
## When Not To Use It
5037

5138
If you want to allow code to `await` non-Promise values.

packages/eslint-plugin/docs/rules/ban-ts-comment.md

+2-24
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,10 @@ The directive comments supported by TypeScript are:
2121
## Rule Details
2222

2323
This rule lets you set which directive comments you want to allow in your codebase.
24-
By default, only `@ts-check` is allowed, as it enables rather than suppresses errors.
25-
26-
The configuration looks like this:
2724

28-
```ts
29-
type DirectiveConfig =
30-
| boolean
31-
| 'allow-with-description'
32-
| { descriptionFormat: string };
33-
34-
interface Options {
35-
'ts-expect-error'?: DirectiveConfig;
36-
'ts-ignore'?: DirectiveConfig;
37-
'ts-nocheck'?: DirectiveConfig;
38-
'ts-check'?: DirectiveConfig;
39-
minimumDescriptionLength?: number;
40-
}
25+
## Options
4126

42-
const defaultOptions: Options = {
43-
'ts-expect-error': 'allow-with-description',
44-
'ts-ignore': true,
45-
'ts-nocheck': true,
46-
'ts-check': false,
47-
minimumDescriptionLength: 3,
48-
};
49-
```
27+
By default, only `@ts-check` is allowed, as it enables rather than suppresses errors.
5028

5129
### `ts-expect-error`, `ts-ignore`, `ts-nocheck`, `ts-check` directives
5230

packages/eslint-plugin/docs/rules/ban-tslint-comment.md

-13
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ someCode(); // tslint:disable-line
3434
someCode(); // This is a comment that just happens to mention tslint
3535
```
3636

37-
## Options
38-
39-
```jsonc
40-
// .eslintrc.json
41-
{
42-
"rules": {
43-
"@typescript-eslint/ban-tslint-comment": "warn"
44-
}
45-
}
46-
```
47-
48-
This rule is not configurable.
49-
5037
## When Not To Use It
5138

5239
If you are still using TSLint.

packages/eslint-plugin/docs/rules/ban-types.md

+68-93
Original file line numberDiff line numberDiff line change
@@ -6,80 +6,61 @@ description: 'Disallow certain types.'
66
>
77
> See **https://typescript-eslint.io/rules/ban-types** for documentation.
88
9-
Some builtin types have aliases, some types are considered dangerous or harmful.
9+
Some built-in types have aliases, while some types are considered dangerous or harmful.
1010
It's often a good idea to ban certain types to help with consistency and safety.
1111

1212
## Rule Details
1313

1414
This rule bans specific types and can suggest alternatives.
1515
Note that it does not ban the corresponding runtime objects from being used.
1616

17-
## Options
18-
19-
```ts
20-
type Options = {
21-
types?: {
22-
[typeName: string]:
23-
| false
24-
| string
25-
| {
26-
message: string;
27-
fixWith?: string;
28-
};
29-
};
30-
extendDefaults?: boolean;
31-
};
32-
```
33-
34-
The rule accepts a single object as options.
35-
36-
### `types`
17+
Examples of code with the default options:
3718

38-
An object whose keys are the types you want to ban, and the values are error messages.
19+
<!--tabs-->
3920

40-
The type can either be a type name literal (`Foo`), a type name with generic parameter instantiation(s) (`Foo<Bar>`), the empty object literal (`{}`), or the empty tuple type (`[]`).
21+
### ❌ Incorrect
4122

42-
The values can be:
23+
```ts
24+
// use lower-case primitives for consistency
25+
const str: String = 'foo';
26+
const bool: Boolean = true;
27+
const num: Number = 1;
28+
const symb: Symbol = Symbol('foo');
29+
const bigInt: BigInt = 1n;
4330

44-
- A string, which is the error message to be reported; or
45-
- `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
46-
- An object with the following properties:
47-
- `message: string` - the message to display when the type is matched.
48-
- `fixWith?: string` - a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
31+
// use a proper function type
32+
const func: Function = () => 1;
4933

50-
### `extendDefaults`
34+
// use safer object types
35+
const lowerObj: Object = {};
36+
const capitalObj: Object = { a: 'string' };
5137

52-
If you're specifying custom `types`, you can set this to `true` to extend the default `types` configuration. This is a convenience option to save you copying across the defaults when adding another type.
38+
const curly1: {} = 1;
39+
const curly2: {} = { a: 'string' };
40+
```
5341

54-
If this is `false`, the rule will _only_ use the types defined in your configuration.
42+
### ✅ Correct
5543

56-
Example configuration:
44+
```ts
45+
// use lower-case primitives for consistency
46+
const str: string = 'foo';
47+
const bool: boolean = true;
48+
const num: number = 1;
49+
const symb: symbol = Symbol('foo');
50+
const bigInt: bigint = 1n;
5751

58-
```jsonc
59-
{
60-
"@typescript-eslint/ban-types": [
61-
"error",
62-
{
63-
"types": {
64-
// add a custom message to help explain why not to use it
65-
"Foo": "Don't use Foo because it is unsafe",
52+
// use a proper function type
53+
const func: () => number = () => 1;
6654

67-
// add a custom message, AND tell the plugin how to fix it
68-
"OldAPI": {
69-
"message": "Use NewAPI instead",
70-
"fixWith": "NewAPI"
71-
},
55+
// use safer object types
56+
const lowerObj: object = {};
57+
const capitalObj: { a: string } = { a: 'string' };
7258

73-
// un-ban a type that's banned by default
74-
"{}": false
75-
},
76-
"extendDefaults": true
77-
}
78-
]
79-
}
59+
const curly1: number = 1;
60+
const curly2: Record<'a', string> = { a: 'string' };
8061
```
8162

82-
### Default Options
63+
## Options
8364

8465
The default options provide a set of "best practices", intended to provide safety and standardization in your codebase:
8566

@@ -122,7 +103,6 @@ const defaultTypes = {
122103
message: 'Use bigint instead',
123104
fixWith: 'bigint',
124105
},
125-
126106
Function: {
127107
message: [
128108
'The `Function` type accepts any function-like value.',
@@ -131,7 +111,6 @@ const defaultTypes = {
131111
'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.',
132112
].join('\n'),
133113
},
134-
135114
// object typing
136115
Object: {
137116
message: [
@@ -152,52 +131,48 @@ const defaultTypes = {
152131

153132
</details>
154133

155-
### Examples
156-
157-
Examples of code with the default options:
158-
159-
<!--tabs-->
134+
### `types`
160135

161-
#### ❌ Incorrect
136+
An object whose keys are the types you want to ban, and the values are error messages.
162137

163-
```ts
164-
// use lower-case primitives for consistency
165-
const str: String = 'foo';
166-
const bool: Boolean = true;
167-
const num: Number = 1;
168-
const symb: Symbol = Symbol('foo');
169-
const bigInt: BigInt = 1n;
138+
The type can either be a type name literal (`Foo`), a type name with generic parameter instantiation(s) (`Foo<Bar>`), the empty object literal (`{}`), or the empty tuple type (`[]`).
170139

171-
// use a proper function type
172-
const func: Function = () => 1;
140+
The values can be:
173141

174-
// use safer object types
175-
const capitalObj1: Object = 1;
176-
const capitalObj2: Object = { a: 'string' };
142+
- A string, which is the error message to be reported; or
143+
- `false` to specifically un-ban this type (useful when you are using `extendDefaults`); or
144+
- An object with the following properties:
145+
- `message: string` - the message to display when the type is matched.
146+
- `fixWith?: string` - a string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
177147

178-
const curly1: {} = 1;
179-
const curly2: {} = { a: 'string' };
180-
```
148+
### `extendDefaults`
181149

182-
#### ✅ Correct
150+
If you're specifying custom `types`, you can set this to `true` to extend the default `types` configuration. This is a convenience option to save you copying across the defaults when adding another type.
183151

184-
```ts
185-
// use lower-case primitives for consistency
186-
const str: string = 'foo';
187-
const bool: boolean = true;
188-
const num: number = 1;
189-
const symb: symbol = Symbol('foo');
190-
const bigInt: bigint = 1n;
152+
If this is `false`, the rule will _only_ use the types defined in your configuration.
191153

192-
// use a proper function type
193-
const func: () => number = () => 1;
154+
Example configuration:
194155

195-
// use safer object types
196-
const lowerObj: object = {};
156+
```jsonc
157+
{
158+
"@typescript-eslint/ban-types": [
159+
"error",
160+
{
161+
"types": {
162+
// add a custom message to help explain why not to use it
163+
"Foo": "Don't use Foo because it is unsafe",
197164

198-
const capitalObj1: number = 1;
199-
const capitalObj2: { a: string } = { a: 'string' };
165+
// add a custom message, AND tell the plugin how to fix it
166+
"OldAPI": {
167+
"message": "Use NewAPI instead",
168+
"fixWith": "NewAPI"
169+
},
200170

201-
const curly1: number = 1;
202-
const curly2: Record<'a', string> = { a: 'string' };
171+
// un-ban a type that's banned by default
172+
"{}": false
173+
},
174+
"extendDefaults": true
175+
}
176+
]
177+
}
203178
```

0 commit comments

Comments
 (0)