Skip to content

Commit

Permalink
test(eslint-plugin): render snapshots of ESLint output for each code …
Browse files Browse the repository at this point in the history
…example (#8497)
  • Loading branch information
auvred authored Apr 4, 2024
1 parent 6e4881c commit a7bdd1c
Show file tree
Hide file tree
Showing 142 changed files with 10,395 additions and 106 deletions.
8 changes: 2 additions & 6 deletions packages/eslint-plugin/docs/rules/ban-ts-comment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ if (false) {
console.log('hello');
}
if (false) {
/*
@ts-ignore: Unreachable code error
*/
/* @ts-ignore: Unreachable code error */
console.log('hello');
}
```
Expand Down Expand Up @@ -90,9 +88,7 @@ if (false) {
console.log('hello');
}
if (false) {
/*
@ts-expect-error: Unreachable code error
*/
/* @ts-expect-error: Unreachable code error */
console.log('hello');
}
```
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/class-methods-use-this.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Example of incorrect code when `ignoreClassesThatImplementAnInterface` is set to
<Tabs>
<TabItem value="❌ Incorrect">

```ts
```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
class X implements Y {
method() {}
property = () => {};
Expand All @@ -86,7 +86,7 @@ class X implements Y {
</TabItem>
<TabItem value="✅ Correct">

```ts
```ts option='{ "ignoreClassesThatImplementAnInterface": "public-fields" }'
class X implements Y {
method() {}
property = () => {};
Expand Down
18 changes: 0 additions & 18 deletions packages/eslint-plugin/docs/rules/consistent-type-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,6 @@ export type { T };
export { x };
```

<Tabs>
<TabItem value="❌ Incorrect">

```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
export { Button } from 'some-library';
export type { ButtonProps } from 'some-library';
```

</TabItem>
<TabItem value="✅ Correct">

```ts option='{ "fixMixedExportsWithInlineTypeSpecifier": true }'
export { Button, type ButtonProps } from 'some-library';
```

</TabItem>
</Tabs>

## When Not To Use It

If you use `--isolatedModules` the compiler would error if a type is not re-exported using `export type`.
Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-plugin/docs/rules/default-param-last.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ It adds support for optional parameters.
<TabItem value="❌ Incorrect">

```ts
/* eslint @typescript-eslint/default-param-last: "error" */

function f(a = 0, b: number) {}
function f(a: number, b = 0, c: number) {}
function f(a: number, b?: number, c: number) {}
Expand All @@ -39,8 +37,6 @@ class Foo {
<TabItem value="✅ Correct">

```ts
/* eslint @typescript-eslint/default-param-last: "error" */

function f(a = 0) {}
function f(a: number, b = 0) {}
function f(a: number, b?: number) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,33 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e.

### `allowArgumentsExplicitlyTypedAsAny`

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

<Tabs>
<TabItem value="❌ Incorrect">
<TabItem value="❌ Incorrect for `allowArgumentsExplicitlyTypedAsAny: false`">

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

</TabItem>
<TabItem value="✅ Correct">
<TabItem value="✅ Correct for `allowArgumentsExplicitlyTypedAsAny: true`">

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

</TabItem>
</Tabs>

### `allowDirectConstAssertionInArrowFunctions`

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

<Tabs>
<TabItem value="❌ Incorrect">
<TabItem value="❌ Incorrect for `allowDirectConstAssertionInArrowFunctions: false`">

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

</TabItem>
<TabItem value="✅ Correct">
<TabItem value="✅ Correct for `allowDirectConstAssertionInArrowFunctions: true`">

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

### `allowHigherOrderFunctions`

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

<Tabs>
<TabItem value="❌ Incorrect">
<TabItem value="❌ Incorrect for `allowHigherOrderFunctions: false`">

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

</TabItem>
<TabItem value="✅ Correct">
<TabItem value="✅ Correct for `allowHigherOrderFunctions: true`">

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

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

### `allowTypedFunctionExpressions`

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

<Tabs>
<TabItem value="❌ Incorrect">
<TabItem value="❌ Incorrect for `allowTypedFunctionExpressions: false`">

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

</TabItem>
<TabItem value="✅ Correct">
<TabItem value="✅ Correct for `allowTypedFunctionExpressions: true`">

```ts option='{ "allowTypedFunctionExpressions": false }'
```ts option='{ "allowTypedFunctionExpressions": true }'
type FuncType = () => string;

export let arrowFn: FuncType = () => 'test';
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-plugin/docs/rules/member-ordering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,9 @@ interface Foo {
b(): void;
a: boolean;

[a: string]: number; // Order doesn't matter (no sortable identifier)
new (): Bar; // Order doesn't matter (no sortable identifier)
(): Baz; // Order doesn't matter (no sortable identifier)
[a: string]: number;
new (): Bar;
(): Baz;
}
```

Expand All @@ -1022,12 +1022,12 @@ interface Foo {

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

[a: string]: number; // Order doesn't matter (no sortable identifier)
new (): Bar; // Order doesn't matter (no sortable identifier)
(): Baz; // Order doesn't matter (no sortable identifier)
(): Baz;
new (): Bar;
}
```

Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/no-extraneous-class.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class NotEmptyClass {

### `allowWithDecorator`

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

<Tabs>
<TabItem value="❌ Incorrect">
Expand All @@ -308,8 +308,8 @@ class Constants {
<TabItem value="✅ Correct">

```ts option='{ "allowWithDecorator": true }'
@logOnRead()
class Constants {
@logOnRead()
static readonly version = 42;
}
```
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-floating-promises.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ This allows you to skip checking of async IIFEs (Immediately Invoked function Ex

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

<!-- prettier-ignore -->
{/* prettier-ignore */}
```ts option='{ "ignoreIIFE": true }' showPlaygroundButton
await (async function () {
await res(1);
Expand Down
4 changes: 0 additions & 4 deletions packages/eslint-plugin/docs/rules/no-implied-eval.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ This rule aims to eliminate implied `eval()` through the use of `new Function()`
<TabItem value="❌ Incorrect">

```ts
/* eslint @typescript-eslint/no-implied-eval: "error" */

setTimeout('alert(`Hi!`);', 100);

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

```ts
/* eslint @typescript-eslint/no-implied-eval: "error" */

setTimeout(function () {
alert('Hi!');
}, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function bar(x: number) {
void x; // discarding a number
return 2;
}
void bar(); // discarding a number
void bar(1); // discarding a number
```

</TabItem>
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/no-require-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ With `{allow: ['/package\\.json$']}`:
<Tabs>
<TabItem value="❌ Incorrect">

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

</TabItem>
<TabItem value="✅ Correct">

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ const bar = foo!;
```

```ts
const foo = <3>3;
const foo = <number>(3 + 5);
```

```ts
type Foo = 3;
const foo = <Foo>3;
type Foo = number;
const foo = <Foo>(3 + 5);
```

```ts
type Foo = 3;
const foo = 3 as Foo;
type Foo = number;
const foo = (3 + 5) as Foo;
```

```ts
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/no-var-requires.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ With `{allow: ['/package\\.json$']}`:
<Tabs>
<TabItem value="❌ Incorrect">

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

</TabItem>
<TabItem value="✅ Correct">

```ts
```ts option='{ "allow": ["/package.json$"] }'
const foo = require('../package.json');
```

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

```ts
const maybe = Math.random() > 0.5 ? '' : undefined;
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;

const definitely = maybe as string;
const alsoDefinitely = <string>maybe;
Expand All @@ -33,7 +33,7 @@ const alsoDefinitely = <string>maybe;
<TabItem value="✅ Correct">

```ts
const maybe = Math.random() > 0.5 ? '' : undefined;
const maybe: string | undefined = Math.random() > 0.5 ? '' : undefined;

const definitely = maybe!;
const alsoDefinitely = maybe!;
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/docs/rules/only-throw-error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ throw `${err}`;
const err = '';
throw err;

function err() {
function getError() {
return '';
}
throw err();
throw getError();

const foo = {
bar: '',
Expand Down Expand Up @@ -70,10 +70,10 @@ try {
const err = new Error();
throw err;

function err() {
function getError() {
return new Error();
}
throw err();
throw getError();

const foo = {
bar: new Error(),
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/prefer-destructuring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ Examples with `{ enforceForDeclarationWithTypeAnnotation: true }`:
<Tabs>
<TabItem value="❌ Incorrect">

```ts
```ts option='{ "object": true }, { "enforceForDeclarationWithTypeAnnotation": true }'
const x: string = obj.x;
```

</TabItem>
<TabItem value="✅ Correct">

```ts
```ts option='{ "object": true }, { "enforceForDeclarationWithTypeAnnotation": true }'
const { x }: { x: string } = obj;
```

Expand Down
Loading

0 comments on commit a7bdd1c

Please sign in to comment.