8000 docs(website): add remark plugin for tabs and apply it to rules · thdk/typescript-eslint@413dfd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 413dfd2

Browse files
committed
docs(website): add remark plugin for tabs and apply it to rules
1 parent 939d8ea commit 413dfd2

25 files changed

+451
-127
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Grouping overloaded members together can improve readability of the code.
66

77
This rule aims to standardize the way overloaded members are organized.
88

9-
The following patterns are considered warnings:
9+
<!--tabs-->
10+
11+
#### Incorrect code
1012

1113
```ts
1214
declare namespace Foo {
@@ -43,7 +45,7 @@ export function bar(): void;
4345
export function foo(sn: string | number): void;
4446
```
4547

46-
The following patterns are not warnings:
48+
#### Correct code
4749

4850
```ts
4951
declare namespace Foo {

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ The default config will enforce that all mutable and readonly arrays use the `'a
3333

3434
Always use `T[]` or `readonly T[]` for all array types.
3535

36-
Incorrect code for `"array"`:
36+
<!--tabs-->
37+
38+
#### Incorrect code
3739

3840
```ts
3941
const x: Array<string> = ['a', 'b'];
4042
const y: ReadonlyArray<string> = ['a', 'b'];
4143
```
4244

43-
Correct code for `"array"`:
45+
#### Correct code
4446

4547
```ts
4648
const x: string[] = ['a', 'b'];
@@ -51,14 +53,16 @@ const y: readonly string[] = ['a', 'b'];
5153

5254
Always use `Array<T>` or `ReadonlyArray<T>` for all array types.
5355

54-
Incorrect code for `"generic"`:
56+
<!--tabs-->
57+
58+
#### Incorrect code
5559

5660
```ts
5761
const x: string[] = ['a', 'b'];
5862
const y: readonly string[] = ['a', 'b'];
5963
```
6064

61-
Correct code for `"generic"`:
65+
#### Correct code
6266

6367
```ts
6468
const x: Array<string> = ['a', 'b'];
@@ -70,7 +74,9 @@ const y: ReadonlyArray<string> = ['a', 'b'];
7074
Use `T[]` or `readonly T[]` for simple types (i.e. types which are just primitive names or type references).
7175
Use `Array<T>` or `ReadonlyArray<T>` for all other types (union types, intersection types, object types, function types, etc).
7276

73-
Incorrect code for `"array-simple"`:
77+
<!--tabs-->
78+
79+
#### Incorrect code
7480

7581
```ts
7682
const a: (string | number)[] = ['a', 'b'];
@@ -81,7 +87,7 @@ const e: Array<string> = ['a', 'b'];
8187
const f: ReadonlyArray<string> = ['a', 'b'];
8288
```
8389

84-
Correct code for `"array-simple"`:
90+
#### Correct code
8591

8692
```ts
8793
const a: Array<string | number> = ['a', 'b'];

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ While it is valid JavaScript to await a non-`Promise`-like value (it will resolv
55

66
## Rule Details
77

8-
Examples of **incorrect** code for this rule:
8+
<!--tabs-->
9+
10+
#### Incorrect code
911

1012
```ts
1113
await 'value';
@@ -14,7 +16,7 @@ const createValue = () => 'value';
1416
await createValue();
1517
```
1618

17-
Examples of **correct** code for this rule:
19+
#### Correct code
1820

1921
```ts
2022
await Promise.resolve('value');

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const defaultOptions: Options = {
4141

4242
A value of `true` for a particular directive means that this rule will report if it finds any usage of said directive.
4343

44-
For example, with the defaults above the following patterns are considered warnings for single line or comment block lines:
44+
<!--tabs-->
45+
46+
#### Incorrect code
4547

4648
```ts
4749
if (false) {
@@ -56,7 +58,7 @@ if (false) {
5658
}
5759
```
5860

59-
The following patterns are not warnings:
61+
#### Correct code
6062

6163
```ts
6264
if (false) {
@@ -69,7 +71,11 @@ if (false) {
6971

7072
A value of `'allow-with-description'` for a particular directive means that this rule will report if it finds a directive that does not have a description following the directive (on the same line).
7173

72-
For example, with `{ 'ts-expect-error': 'allow-with-description' }` the following patterns are considered a warning:
74+
For example, with `{ 'ts-expect-error': 'allow-with-description' }`:
75+
76+
<!--tabs-->
77+
78+
#### Incorrect code
7379

7480
```ts
7581
if (false) {
@@ -82,7 +88,7 @@ if (false) {
8288
}
8389
```
8490

85-
The following patterns are not a warning:
91+
#### Correct code
8692

8793
```ts
8894
if (false) {
@@ -101,7 +107,11 @@ if (false) {
101107

102108
Use `minimumDescriptionLength` to set a minimum length for descriptions when using the `allow-with-description` option for a directive.
103109

104-
For example, with `{ 'ts-expect-error': 'allow-with-description', minimumDescriptionLength: 10 }` the following pattern is considered a warning:
110+
For example, with `{ 'ts-expect-error': 'allow-with-description', minimumDescriptionLength: 10 }` the following pattern is:
111+
112+
<!--tabs-->
113+
114+
#### Incorrect code
105115

106116
```ts
107117
if (false) {
@@ -110,7 +120,7 @@ if (false) {
110120
}
111121
```
112122

113-
The following pattern is not a warning:
123+
#### Correct code
114124

115125
```ts
116126
if (false) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Useful when migrating from TSLint to ESLint. Once TSLint has been removed, this
44

55
## Rule Details
66

7-
Examples of **incorrect** code for this rule:
8-
97
All TSLint [rule flags](https://palantir.github.io/tslint/usage/rule-flags/)
108

9+
<!--tabs-->
10+
11+
#### Incorrect code
12+
1113
```js
1214
/* tslint:disable */
1315
/* tslint:enable */
@@ -18,10 +20,12 @@ someCode(); // tslint:disable-line
1820
// tslint:disable-next-line:rule1 rule2 rule3...
1921
```
2022

21-
Examples of **correct** code for this rule:
23+
#### Correct code
2224

2325
```js
2426
// This is a comment that just happens to mention tslint
27+
/* This is a multiline comment that just happens to mention tslint */
28+
someCode(); // This is a comment that just happens to mention tslint
2529
```
2630

2731
## When Not To Use It

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ const defaultTypes = {
131131

132132
### Examples
133133

134-
Examples of **incorrect** code with the default options:
134+
Examples of code with the default options:
135+
136+
<!--tabs-->
137+
138+
#### Incorrect code
135139

136140
```ts
137141
// use lower-case primitives for consistency
@@ -151,7 +155,7 @@ const curly1: {} = 1;
151155
const curly2: {} = { a: 'string' };
152156
```
153157

154-
Examples of **correct** code with the default options:
158+
#### Correct code
155159

156160
```ts
157161
// use lower-case primitives for consistency

packages/eslint-plugin/docs/rules/class-literal-property-style.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,41 @@ This is because these types can be mutated and carry with them more complex impl
1515

1616
This style checks for any getter methods that return literal values, and requires them to be defined using fields with the `readonly` modifier instead.
1717

18-
Examples of **correct** code with the `fields` style:
18+
Examples of code with the `fields` style:
19+
20+
<!--tabs-->
21+
22+
#### Incorrect code
1923

2024
```ts
2125
/* eslint @typescript-eslint/class-literal-property-style: ["error", "fields"] */
2226

2327
class Mx {
24-
public readonly myField1 = 1;
25-
26-
// not a literal
27-
public readonly myField2 = [1, 2, 3];
28-
29-
private readonly ['myField3'] = 'hello world';
28+
public static get myField1() {
29+
return 1;
30+
}
3031

31-
public get myField4() {
32-
return `hello from ${window.location.href}`;
32+
private get ['myField2']() {
33+
return 'hello world';
3334
}
3435
}
3536
```
3637

37-
Examples of **incorrect** code with the `fields` style:
38+
#### Correct code
3839

3940
```ts
4041
/* eslint @typescript-eslint/class-literal-property-style: ["error", "fields"] */
4142

4243
class Mx {
43-
public static get myField1() {
44-
return 1;
45-
}
44+
public readonly myField1 = 1;
4645

47-
private get ['myField2']() {
48-
return 'hello world';
46+
// not a literal
47+
public readonly myField2 = [1, 2, 3];
48+
49+
private readonly ['myField3'] = 'hello world';
50+
51+
public get myField4() {
52+
return `hello from ${window.location.href}`;
4953
}
5054
}
5155
```
@@ -56,7 +60,23 @@ This style checks for any `readonly` fields that are assigned literal values, an
5660
This style pairs well with the [`@typescript-eslint/prefer-readonly`](prefer-readonly.md) rule,
5761
as it will identify fields that can be `readonly`, and thus should be made into getters.
5862

59-
Examples of **correct** code with the `getters` style:
63+
Examples of code with the `getters` style:
64+
65+
<!--tabs-->
66+
67+
#### Incorrect code
68+
69+
```ts
70+
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */
71+
72+
class Mx {
73+
readonly myField1 = 1;
74+
readonly myField2 = `hello world`;
75+
private readonly myField3 = 'hello world';
76+
}
77+
```
78+
79+
#### Correct code
6080

6181
```ts
6282
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */
@@ -78,18 +98,6 @@ class Mx {
7898
}
7999
```
80100

81-
Examples of **incorrect** code with the `getters` style:
82-
83-
```ts
84-
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */
85-
86-
class Mx {
87-
readonly myField1 = 1;
88-
readonly myField2 = `hello world`;
89-
private readonly myField3 = 'hello world';
90-
}
91-
```
92-
93101
## When Not To Use It
94102

95103
When you have no strong preference, or do not wish to enforce a particular style

packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ For example:
3333

3434
This rule enforces a consistent way to define records.
3535

36-
Examples of **incorrect** code with `record` option.
36+
### `record`
37+
38+
Examples of code with `record` option.
39+
40+
<!--tabs-->
41+
42+
#### Incorrect code
3743

3844
```ts
3945
interface Foo {
@@ -45,19 +51,25 @@ type Foo = {
4551
};
4652
```
4753

48-
Examples of **correct** code with `record` option.
54+
#### Correct code
4955

5056
```ts
5157
type Foo = Record<string, unknown>;
5258
```
5359

54-
Examples of **incorrect** code with `index-signature` option.
60+
### `index-signature`
61+
62+
Examples of code with `index-signature` option.
63+
64+
<!--tabs-->
65+
66+
#### Incorrect code
5567

5668
```ts
5769
type Foo = Record<string, unknown>;
5870
```
5971

60-
Examples of **correct** code with `index-signature` option.
72+
#### Correct code
6173

6274
```ts
6375
interface Foo {

0 commit comments

Comments
 (0)
0