Skip to content

Commit ce27488

Browse files
authored
docs: various improvements to documentations (typescript-eslint#4219)
* docs: various improvements to documentations * chore: use remark-docusaurus-tabs
1 parent 0040186 commit ce27488

File tree

9 files changed

+40
-162
lines changed

9 files changed

+40
-162
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ The default options provide a set of "best practices", intended to provide safet
7676
- This is a point of confusion for many developers, who think it means "any object type".
7777
- See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492).
7878

79-
**_Important note:_** the default options suggest using `Record<string, unknown>`; this was a stylistic decision, as the built-in `Record` type is considered to look cleaner.
79+
:::important
80+
81+
The default options suggest using `Record<string, unknown>`; this was a stylistic decision, as the built-in `Record` type is considered to look cleaner.
82+
83+
:::
8084

8185
<details>
8286
<summary>Default Options</summary>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ When writing TypeScript libraries that could be used by JavaScript users however
88
This rule aims to ensure that literals exposed by classes are done so consistently, in one of the two style described above.
99
By default this rule prefers the `fields` style as it means JS doesn't have to setup & teardown a function closure.
1010

11-
Note that this rule only checks for constant _literal_ values (string, template string, number, bigint, boolean, regexp, null). It does not check objects or arrays, because a readonly field behaves differently to a getter in those cases. It also does not check functions, as it is a common pattern to use readonly fields with arrow function values as auto-bound methods.
11+
:::note
12+
13+
This rule only checks for constant _literal_ values (string, template string, number, bigint, boolean, regexp, null). It does not check objects or arrays, because a readonly field behaves differently to a getter in those cases. It also does not check functions, as it is a common pattern to use readonly fields with arrow function values as auto-bound methods.
1214
This is because these types can be mutated and carry with them more complex implications about their usage.
1315

16+
:::
17+
1418
### The `fields` style
1519

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

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const [a] = [1];
8888
const [b, c] = [1, 2];
8989
```
9090

91-
#### Correct
91+
#### Correct
9292

9393
```ts
9494
const [a]: number[] = [1];
@@ -119,7 +119,7 @@ const mapper = {
119119
};
120120
```
121121

122-
#### Correct
122+
#### Correct
123123

124124
```ts
125125
const logsSize = (size: number) => console.log(size);
@@ -148,7 +148,7 @@ class ContainsText {
148148
}
149149
```
150150

151-
#### Correct
151+
#### Correct
152152

153153
```ts
154154
class ContainsText {
@@ -172,7 +172,7 @@ const { length } = 'text';
172172
const [b, c] = Math.random() ? [1, 2] : [3, 4];
173173
```
174174

175-
#### Correct
175+
#### Correct
176176

177177
```ts
178178
const { length }: { length: number } = 'text';
@@ -218,7 +218,7 @@ class Logger {
218218
}
219219
```
220220

221-
#### Correct
221+
#### Correct
222222

223223
```ts
224224
function logsSize(size: number): void {
@@ -263,7 +263,7 @@ type Members = {
263263
};
264264
```
265265

266-
#### Correct
266+
#### Correct
267267

268268
```ts
269269
type Members = {
@@ -288,7 +288,7 @@ let initialText = 'text';
288288
let delayedText;
289289
```
290290

291-
#### Correct
291+
#### Correct
292292

293293
```ts
294294
const text: string = 'text';
@@ -310,7 +310,7 @@ Examples of code with `{ "variableDeclaration": true, "variableDeclarationIgnore
310310
const text = 'text';
311311
```
312312

313-
#### Correct
313+
#### Correct
314314

315315
```ts
316316
const a = (): void => {};

packages/eslint-plugin/docs/rules/unified-signatures.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,30 @@ Warns for any two overloads that could be unified into one by using a union or a
66

77
This rule aims to keep the source code as maintainable as possible by reducing the amount of overloads.
88

9-
Examples of **incorrect** code for this rule:
9+
Examples of code for this rule:
10+
11+
<!--tabs-->
12+
13+
### ❌ Incorrect
1014

1115
```ts
12-
function f(x: number): void;
13-
function f(x: string): void;
16+
function x(x: number): void;
17+
function x(x: string): void;
1418
```
1519

1620
```ts
17-
f(): void;
18-
f(...x: number[]): void;
21+
function y(): void;
22+
function y(...x: number[]): void;
1923
```
2024

21-
Examples of **correct** code for this rule:
25+
### ✅ Correct
2226

2327
```ts
24-
function f(x: number | string): void;
28+
function x(x: number | string): void;
2529
```
2630

2731
```ts
28-
function f(x?: ...number[]): void;
32+
function y(...x: number[]): void;
2933
```
3034

3135
## Related to

packages/website/docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const remarkPlugins = [
88
[require('@docusaurus/remark-plugin-npm2yarn'), { sync: true }],
99
];
1010

11-
const beforeDefaultRemarkPlugins = [[require('./src/remark/tabs'), {}]];
11+
const beforeDefaultRemarkPlugins = [[require('remark-docusaurus-tabs'), {}]];
1212

1313
const githubUrl = 'https://github.com/typescript-eslint/typescript-eslint';
1414

packages/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"konamimojisplosion": "^0.5.1",
3232
"react": "^17.0.2",
3333
"react-dom": "^17.0.2",
34+
"remark-docusaurus-tabs": "^0.2.0",
3435
"typescript": "*"
3536
},
3637
"devDependencies": {

packages/website/src/remark/tabs.js

Lines changed: 0 additions & 120 deletions
This file was deleted.

packages/website/src/remark/tabs.license.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12166,6 +12166,14 @@ remark-admonitions@^1.2.1:
1216612166
unified "^8.4.2"
1216712167
unist-util-visit "^2.0.1"
1216812168

12169+
remark-docusaurus-tabs@^0.2.0:
12170+
version "0.2.0"
12171+
resolved "https://registry.yarnpkg.com/remark-docusaurus-tabs/-/remark-docusaurus-tabs-0.2.0.tgz#39e02b2e72a68458c1c11003e95ddb7d236e8006"
12172+
integrity sha512-Xl8FkeQAdDqlhf7EurBxCkT7cfA5QK2PN8eoFr94g1OOuc7XsgVk897zf8yhNNnpQYR8nd/XC6JaXTZxHxX4mA==
12173+
dependencies:
12174+
mdast-util-to-string "^2.0.0"
12175+
unist-util-visit "^2.0.3"
12176+
1216912177
remark-emoji@^2.1.0:
1217012178
version "2.2.0"
1217112179
resolved "https://registry.yarnpkg.com/remark-emoji/-/remark-emoji-2.2.0.tgz#1c702090a1525da5b80e15a8f963ef2c8236cac7"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy