Skip to content

Commit a7bdd1c

Browse files
authored
test(eslint-plugin): render snapshots of ESLint output for each code example (#8497)
1 parent 6e4881c commit a7bdd1c

File tree

142 files changed

+10395
-106
lines changed

Some content is hidden

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

142 files changed

+10395
-106
lines changed

Diff for: packages/eslint-plugin/docs/rules/ban-ts-comment.mdx

+2-6
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ if (false) {
4141
console.log('hello');
4242
}
4343
if (false) {
44-
/*
45-
@ts-ignore: Unreachable code error
46-
*/
44+
/* @ts-ignore: Unreachable code error */
4745
console.log('hello');
4846
}
4947
```
@@ -90,9 +88,7 @@ if (false) {
9088
console.log('hello');
9189
}
9290
if (false) {
93-
/*
94-
@ts-expect-error: Unreachable code error
95-
*/
91+
/* @ts-expect-error: Unreachable code error */
9692
console.log('hello');
9793
}
9894
```

Diff for: packages/eslint-plugin/docs/rules/class-methods-use-this.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Example of incorrect code when `ignoreClassesThatImplementAnInterface` is set to
7070
<Tabs>
7171
<TabItem value="❌ Incorrect">
7272

73-
```ts
73+
```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
7474
class X implements Y {
7575
method() {}
7676
property = () => {};
@@ -86,7 +86,7 @@ class X implements Y {
8686
</TabItem>
8787
<TabItem value="✅ Correct">
8888

89-
```ts
89+
```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
9090
class X implements Y {
9191
method() {}
9292
property = () => {};

Diff for: packages/eslint-plugin/docs/rules/consistent-type-exports.mdx

-18
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,6 @@ export type { T };
8585
export { x };
8686
```
8787

88-
<Tabs>
89-
<TabItem value="❌ Incorrect">
90-
91-
```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
92-
export { Button } from 'some-library';
93-
export type { ButtonProps } from 'some-library';
94-
```
95-
96-
</TabItem>
97-
<TabItem value="✅ Correct">
98-
99-
```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
100-
export { Button, type ButtonProps } from 'some-library';
101-
```
102-
103-
</TabItem>
104-
</Tabs>
105-
10688
## When Not To Use It
10789

10890
If you use `--isolatedModules` the compiler would error if a type is not re-exported using `export type`.

Diff for: packages/eslint-plugin/docs/rules/default-param-last.mdx

-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ It adds support for optional parameters.
1616
<TabItem value="❌ Incorrect">
1717

1818
```ts
19-
/* eslint @typescript-eslint/default-param-last: "error" */
20-
2119
function f(a = 0, b: number) {}
2220
function f(a: number, b = 0, c: number) {}
2321
function f(a: number, b?: number, c: number) {}
@@ -39,8 +37,6 @@ class Foo {
3937
<TabItem value="✅ Correct">
4038

4139
```ts
42-
/* eslint @typescript-eslint/default-param-last: "error" */
43-
4440
function f(a = 0) {}
4541
function f(a: number, b = 0) {}
4642
function f(a: number, b?: number) {}

Diff for: packages/eslint-plugin/docs/rules/explicit-module-boundary-types.mdx

+18-18
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,33 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e.
9797

9898
### `allowArgumentsExplicitlyTypedAsAny`
9999

100-
Examples of code for this rule with `{ allowArgumentsExplicitlyTypedAsAny: false }`:
100+
When this option is `true`, the rule ignores arguments that are explicitly typed as any.
101101

102102
<Tabs>
103-
<TabItem value="❌ Incorrect">
103+
<TabItem value="❌ Incorrect for `allowArgumentsExplicitlyTypedAsAny: false`">
104104

105105
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
106106
export const func = (value: any): number => value + 1;
107107
```
108108

109109
</TabItem>
110-
<TabItem value="✅ Correct">
110+
<TabItem value="✅ Correct for `allowArgumentsExplicitlyTypedAsAny: true`">
111111

112-
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
113-
export const func = (value: number): number => value + 1;
112+
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": true }'
113+
export const func = (value: any): number => value + 1;
114114
```
115115

116116
</TabItem>
117117
</Tabs>
118118

119119
### `allowDirectConstAssertionInArrowFunctions`
120120

121-
Examples of code for this rule with `{ allowDirectConstAssertionInArrowFunctions: false }`:
121+
When this option is `true`, the rule ignores return type annotations on body-less arrow functions that return an `as const` type assertion.
122122

123123
<Tabs>
124-
<TabItem value="❌ Incorrect">
124+
<TabItem value="❌ Incorrect for `allowDirectConstAssertionInArrowFunctions: false`">
125125

126-
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
126+
```ts option='{ "allowDirectConstAssertionInArrowFunctions": false }'
127127
export const func = (value: number) => ({ type: 'X', value });
128128
export const foo = () => ({
129129
bar: true,
@@ -132,9 +132,9 @@ export const bar = () => 1;
132132
```
133133

134134
</TabItem>
135-
<TabItem value="✅ Correct">
135+
<TabItem value="✅ Correct for `allowDirectConstAssertionInArrowFunctions: true`">
136136

137-
```ts option='{ "allowArgumentsExplicitlyTypedAsAny": false }'
137+
```ts option='{ "allowDirectConstAssertionInArrowFunctions": true }'
138138
export const func = (value: number) => ({ type: 'X', value }) as const;
139139
export const foo = () =>
140140
({
@@ -163,10 +163,10 @@ You may pass function/method names you would like this rule to ignore, like so:
163163

164164
### `allowHigherOrderFunctions`
165165

166-
Examples of code for this rule with `{ allowHigherOrderFunctions: false }`:
166+
When this option is `true`, the rule ignores return type annotations on function, which is immediately returning another function expression.
167167

168168
<Tabs>
169-
<TabItem value="❌ Incorrect">
169+
<TabItem value="❌ Incorrect for `allowHigherOrderFunctions: false`">
170170

171171
```ts option='{ "allowHigherOrderFunctions": false }'
172172
export const arrowFn = () => () => {};
@@ -181,9 +181,9 @@ export function foo(outer: string) {
181181
```
182182

183183
</TabItem>
184-
<TabItem value="✅ Correct">
184+
<TabItem value="✅ Correct for `allowHigherOrderFunctions: true`">
185185

186-
```ts option='{ "allowHigherOrderFunctions": false }'
186+
```ts option='{ "allowHigherOrderFunctions": true }'
187187
export const arrowFn = () => (): void => {};
188188

189189
export function fn() {
@@ -200,10 +200,10 @@ export function foo(outer: string) {
200200

201201
### `allowTypedFunctionExpressions`
202202

203-
Examples of code for this rule with `{ allowTypedFunctionExpressions: false }`:
203+
When this option is `true`, the rule ignores type annotations on the variable of a function expression.
204204

205205
<Tabs>
206-
<TabItem value="❌ Incorrect">
206+
<TabItem value="❌ Incorrect for `allowTypedFunctionExpressions: false`">
207207

208208
```ts option='{ "allowTypedFunctionExpressions": false }'
209209
export let arrowFn = () => 'test';
@@ -220,9 +220,9 @@ export const foo = bar => {};
220220
```
221221

222222
</TabItem>
223-
<TabItem value="✅ Correct">
223+
<TabItem value="✅ Correct for `allowTypedFunctionExpressions: true`">
224224

225-
```ts option='{ "allowTypedFunctionExpressions": false }'
225+
```ts option='{ "allowTypedFunctionExpressions": true }'
226226
type FuncType = () => string;
227227

228228
export let arrowFn: FuncType = () => 'test';

Diff for: packages/eslint-plugin/docs/rules/member-ordering.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,9 @@ interface Foo {
10111011
b(): void;
10121012
a: boolean;
10131013

1014-
[a: string]: number; // Order doesn't matter (no sortable identifier)
1015-
new (): Bar; // Order doesn't matter (no sortable identifier)
1016-
(): Baz; // Order doesn't matter (no sortable identifier)
1014+
[a: string]: number;
1015+
new (): Bar;
1016+
(): Baz;
10171017
}
10181018
```
10191019

@@ -1022,12 +1022,12 @@ interface Foo {
10221022

10231023
```ts option='{ "default": { "memberTypes": "never", "order": "alphabetically" } }'
10241024
interface Foo {
1025+
[a: string]: number;
10251026
a: boolean;
10261027
b(): void;
10271028

1028-
[a: string]: number; // Order doesn't matter (no sortable identifier)
1029-
new (): Bar; // Order doesn't matter (no sortable identifier)
1030-
(): Baz; // Order doesn't matter (no sortable identifier)
1029+
(): Baz;
1030+
new (): Bar;
10311031
}
10321032
```
10331033

Diff for: packages/eslint-plugin/docs/rules/no-extraneous-class.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class NotEmptyClass {
293293

294294
### `allowWithDecorator`
295295

296-
The `allowWithDecorator` option adds an exemption for classes that contain a member decorated with a `@` decorator.
296+
The `allowWithDecorator` option adds an exemption for classes decorated with a `@` decorator.
297297

298298
<Tabs>
299299
<TabItem value="❌ Incorrect">
@@ -308,8 +308,8 @@ class Constants {
308308
<TabItem value="✅ Correct">
309309

310310
```ts option='{ "allowWithDecorator": true }'
311+
@logOnRead()
311312
class Constants {
312-
@logOnRead()
313313
static readonly version = 42;
314314
}
315315
```

Diff for: packages/eslint-plugin/docs/rules/no-floating-promises.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ This allows you to skip checking of async IIFEs (Immediately Invoked function Ex
104104

105105
Examples of **correct** code for this rule with `{ ignoreIIFE: true }`:
106106

107-
<!-- prettier-ignore -->
107+
{/* prettier-ignore */}
108108
```ts option='{ "ignoreIIFE": true }' showPlaygroundButton
109109
await (async function () {
110110
await res(1);

Diff for: packages/eslint-plugin/docs/rules/no-implied-eval.mdx

-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ This rule aims to eliminate implied `eval()` through the use of `new Function()`
3636
<TabItem value="❌ Incorrect">
3737

3838
```ts
39-
/* eslint @typescript-eslint/no-implied-eval: "error" */
40-
4139
setTimeout('alert(`Hi!`);', 100);
4240

4341
setInterval('alert(`Hi!`);', 100);
@@ -65,8 +63,6 @@ const fn = new Function('a', 'b', 'return a + b');
6563
<TabItem value="✅ Correct">
6664

6765
```ts
68-
/* eslint @typescript-eslint/no-implied-eval: "error" */
69-
7066
setTimeout(function () {
7167
alert('Hi!');
7268
}, 100);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function bar(x: number) {
4444
void x; // discarding a number
4545
return 2;
4646
}
47-
void bar(); // discarding a number
47+
void bar(1); // discarding a number
4848
```
4949

5050
</TabItem>

Diff for: packages/eslint-plugin/docs/rules/no-require-imports.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ With `{allow: ['/package\\.json$']}`:
4545
<Tabs>
4646
<TabItem value="❌ Incorrect">
4747

48-
```ts
48+
```ts option='{ "allow": ["/package.json$"] }'
4949
console.log(require('../data.json').version);
5050
```
5151

5252
</TabItem>
5353
<TabItem value="✅ Correct">
5454

55-
```ts
55+
```ts option='{ "allow": ["/package.json$"] }'
5656
console.log(require('../package.json').version);
5757
```
5858

Diff for: packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ const bar = foo!;
2424
```
2525

2626
```ts
27-
const foo = <3>3;
27+
const foo = <number>(3 + 5);
2828
```
2929

3030
```ts
31-
type Foo = 3;
32-
const foo = <Foo>3;
31+
type Foo = number;
32+
const foo = <Foo>(3 + 5);
3333
```
3434

3535
```ts
36-
type Foo = 3;
37-
const foo = 3 as Foo;
36+
type Foo = number;
37+
const foo = (3 + 5) as Foo;
3838
```
3939

4040
```ts

Diff for: packages/eslint-plugin/docs/rules/no-var-requires.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ With `{allow: ['/package\\.json$']}`:
4545
<Tabs>
4646
<TabItem value="❌ Incorrect">
4747

48-
```ts
48+
```ts option='{ "allow": ["/package.json$"] }'
4949
const foo = require('../data.json');
5050
```
5151

5252
</TabItem>
5353
<TabItem value="✅ Correct">
5454

55-
```ts
55+
```ts option='{ "allow": ["/package.json$"] }'
5656
const foo = require('../package.json');
5757
```
5858

Diff for: packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This rule reports when an `as` cast is doing the same job as a `!` would, and su
2323
<TabItem value="❌ Incorrect">
2424

2525
```ts
26-
const maybe = Math.random() > 0.5 ? '' : undefined;
26+
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;
2727

2828
const definitely = maybe as string;
2929
const alsoDefinitely = <string>maybe;
@@ -33,7 +33,7 @@ const alsoDefinitely = <string>maybe;
3333
<TabItem value="✅ Correct">
3434

3535
```ts
36-
const maybe = Math.random() > 0.5 ? '' : undefined;
36+
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;
3737

3838
const definitely = maybe!;
3939
const alsoDefinitely = maybe!;

Diff for: packages/eslint-plugin/docs/rules/only-throw-error.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ throw `${err}`;
3939
const err = '';
4040
throw err;
4141

42-
function err() {
42+
function getError() {
4343
return '';
4444
}
45-
throw err();
45+
throw getError();
4646

4747
const foo = {
4848
bar: '',
@@ -70,10 +70,10 @@ try {
7070
const err = new Error();
7171
throw err;
7272

73-
function err() {
73+
function getError() {
7474
return new Error();
7575
}
76-
throw err();
76+
throw getError();
7777

7878
const foo = {
7979
bar: new Error(),

Diff for: packages/eslint-plugin/docs/rules/prefer-destructuring.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ Examples with `{ enforceForDeclarationWithTypeAnnotation: true }`:
8787
<Tabs>
8888
<TabItem value="❌ Incorrect">
8989

90-
```ts
90+
```ts option='{ "object": true }, { "enforceForDeclarationWithTypeAnnotation": true }'
9191
const x: string = obj.x;
9292
```
9393

9494
</TabItem>
9595
<TabItem value="✅ Correct">
9696

97-
```ts
97+
```ts option='{ "object": true }, { "enforceForDeclarationWithTypeAnnotation": true }'
9898
const { x }: { x: string } = obj;
9999
```
100100

0 commit comments

Comments
 (0)