Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(eslint-plugin): render snapshots of ESLint output for each code example #8497

Merged
merged 27 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b4e39fb
test(eslint-plugin): render snapshots of ESLint output for each code …
auvred Feb 17, 2024
a2205ed
refactor a bit + render options in snapshots
auvred Feb 17, 2024
7c1e3cb
fix lint issues
auvred Feb 17, 2024
41092d1
sync snapshots for ignored rules
auvred Feb 17, 2024
7f53772
sync description for allowWithDecorator option of no-extraneous-class
auvred Feb 18, 2024
ae79d03
add missing commas in explicit-module-boundary-types.md
auvred Feb 18, 2024
4fcedd5
more accurate squiggles
auvred Feb 18, 2024
aefbf8d
Merge branch 'main' into chore/8382
auvred Feb 23, 2024
85c1edf
add `skipValidation` check
auvred Feb 23, 2024
a7f7e6a
check for unused skipValidation usages
auvred Feb 23, 2024
125eb31
validate options against rule options schema
auvred Feb 24, 2024
329c348
Merge branch 'main' into chore/8382
auvred Feb 24, 2024
f9c4498
sync snapshots with main
auvred Feb 24, 2024
c28fdf2
fix prefer-optional-chain's checkBoolean docs
auvred Feb 24, 2024
4cfa5be
Merge branch 'main' into chore/8382
auvred Mar 3, 2024
f20fed9
Update packages/eslint-plugin/docs/rules/explicit-module-boundary-typ…
auvred Mar 6, 2024
4b6fc6a
Merge branch 'main' into chore/8382
auvred Mar 6, 2024
db55e81
sync snapshots with main
auvred Mar 6, 2024
fad3342
chore: merge main
auvred Mar 22, 2024
2797550
chore: merge main
auvred Apr 3, 2024
7c279fa
support mdx v3 + sync snapshots
auvred Apr 3, 2024
ba833b5
sync yarn lockfile
auvred Apr 3, 2024
104b154
cleanup
auvred Apr 3, 2024
113b217
Merge branch 'main' into chore/8382
auvred Apr 3, 2024
daa1dd8
correct spelling
auvred Apr 3, 2024
dd275e2
fix windows snapshots (maybe?)
auvred Apr 3, 2024
25c8102
Merge branch 'main' into chore/8382
bradzacher Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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