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

Enhance "all" configuration and update documentation #578

Merged
merged 7 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 78 additions & 46 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/rules/consistent-test-filename.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Require .spec test file pattern (`vitest/consistent-test-filename`)

⚠️ This rule _warns_ in the 🌐 `all` config.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason why this was removed? It's generated by a tool we use to keep documentation updated. Did you removed it manually?

Copy link
Contributor Author

@y-hsgw y-hsgw Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veritem

Is there any specific reason why this was removed?

Since the information is already documented in the All section, I determined that it is unnecessary to include it in each individual rule's documentation.

It's generated by a tool we use to keep documentation updated. Did you removed it manually?

Oh, I see... I didn't realize that and ended up removing it manually. 🥲
Are you referring to the script below?

"update:eslint-docs": "pnpm build && eslint-doc-generator",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't mind, you can get them back and I'll go a head and merge your PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted it in commit 62cd790.
Should we add the note "This rule warns in the 🌐 all config." to the documentation for the rules that were enabled this time (e.g., expect-expect, no-commented-out-tests, etc.)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhmm, it's supposed to be done by eslint-doc-generator automatically but it hasn't added support for flat config.

Should we add the note "This rule warns in the 🌐 all config." to the documentation for the rules that were enabled this time

yes!

Copy link
Contributor Author

@y-hsgw y-hsgw Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the notes in ce2114a.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing, did you run this command update:eslint-docs? I think some things on readme have been modified which shouldn't be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you run this command update:eslint-docs?

No, I haven't run it.

I think some things on readme have been modified which shouldn't be modified.

Which part are you referring to? The Rules section?

Copy link
Member

@veritem veritem Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part are you referring to? The Rules section?

Yes, the rules section should remain as it is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed in 488a269.


<!-- end auto-generated rule header -->

Expand Down
2 changes: 0 additions & 2 deletions docs/rules/consistent-test-it.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using test or it but not both (`vitest/consistent-test-it`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down Expand Up @@ -87,4 +86,3 @@ it.only('it works', () => { // <-- Invalid
```

The default configuration is top level `test` and all tests nested with `describe` to use `it`.

1 change: 0 additions & 1 deletion docs/rules/max-expect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce a maximum number of expect per test (`vitest/max-expect`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/max-expects.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce a maximum number of expect per test (`vitest/max-expects`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/max-nested-describe.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Require describe block to be less than set max value or default value (`vitest/max-nested-describe`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-alias-methods.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow alias methods (`vitest/no-alias-methods`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-conditional-expect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow conditional expects (`vitest/no-conditional-expect`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-conditional-in-test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow conditional tests (`vitest/no-conditional-in-test`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->
### Rule Details
Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-conditional-tests.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow conditional tests (`vitest/no-conditional-tests`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-disabled-tests.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow disabled tests (`vitest/no-disabled-tests`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-done-callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

❌ This rule is deprecated.

⚠️ This rule _warns_ in the 🌐 `all` config.

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-duplicate-hooks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow duplicate hooks and teardown hooks (`vitest/no-duplicate-hooks`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand All @@ -25,4 +24,3 @@ test('foo', () => {
beforeEach(() => {})
})
```

1 change: 0 additions & 1 deletion docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow focused tests (`vitest/no-focused-tests`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-hooks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow setup and teardown hooks (`vitest/no-hooks`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-interpolation-in-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow string interpolation in snapshots (`vitest/no-interpolation-in-snapshots`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-large-snapshots.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow large snapshots (`vitest/no-large-snapshots`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down Expand Up @@ -51,4 +50,3 @@ test('large snapshot', () => {
## When Not To Use It

If you don't want to limit the size of your snapshots, you can disable this rule.

1 change: 0 additions & 1 deletion docs/rules/no-mocks-import.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow importing from __mocks__ directory (`vitest/no-mocks-import`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-restricted-matchers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow the use of certain matchers (`vitest/no-restricted-matchers`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-restricted-vi-methods.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow specific `vi.` methods (`vitest/no-restricted-vi-methods`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-standalone-expect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow using `expect` outside of `it` or `test` blocks (`vitest/no-standalone-expect`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-test-prefixes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow using `test` as a prefix (`vitest/no-test-prefixes`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-test-return-statement.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Disallow return statements in tests (`vitest/no-test-return-statement`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-called-with.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using `toBeCalledWith()` or `toHaveBeenCalledWith()` (`vitest/prefer-called-with`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-comparison-matcher.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using the built-in comparison matchers (`vitest/prefer-comparison-matcher`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-each.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using `each` rather than manual loops (`vitest/prefer-each`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
5 changes: 2 additions & 3 deletions docs/rules/prefer-equality-matcher.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using the built-in quality matchers (`vitest/prefer-equality-matcher`)

⚠️ This rule _warns_ in the 🌐 `all` config.

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand All @@ -13,9 +12,9 @@ This rule aims to enforce the use of the built-in equality matchers.
Examples of **incorrect** code for this rule:

```ts
// bad
// bad
expect(1 == 1).toBe(1)


// bad
expect(1).toEqual(1)
Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-expect-assertions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using expect assertions instead of callbacks (`vitest/prefer-expect-assertions`)

⚠️ This rule _warns_ in the 🌐 `all` config.

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand Down
5 changes: 2 additions & 3 deletions docs/rules/prefer-expect-resolves.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Enforce using `expect().resolves` over `expect(await ...)` syntax (`vitest/prefer-expect-resolves`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

```ts
// bad
// bad
it('passes', async () => { expect(await someValue()).toBe(true); });

// good
// good
it('passes', async () => { await expect(someValue()).resolves.toBe(true); });
```
3 changes: 1 addition & 2 deletions docs/rules/prefer-hooks-in-order.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Enforce having hooks in consistent order (`vitest/prefer-hooks-in-order`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

```js
```js
// consistent order of hooks
['beforeAll', 'beforeEach', 'afterEach', 'afterAll']
```
Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-hooks-on-top.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce having hooks before any test cases (`vitest/prefer-hooks-on-top`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->
```ts
Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-lowercase-title.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce lowercase titles (`vitest/prefer-lowercase-title`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-mock-promise-shorthand.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce mock resolved/rejected shorthands for promises (`vitest/prefer-mock-promise-shorthand`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-snapshot-hint.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce including a hint with external snapshots (`vitest/prefer-snapshot-hint`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-spy-on.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using `vi.spyOn` (`vitest/prefer-spy-on`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-strict-equal.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce strict equal over equal (`vitest/prefer-strict-equal`)

⚠️ This rule _warns_ in the 🌐 `all` config.

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand Down
2 changes: 0 additions & 2 deletions docs/rules/prefer-to-be-falsy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using toBeFalsy() (`vitest/prefer-to-be-falsy`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand All @@ -23,4 +22,3 @@ Examples of **correct** code for this rule:
expect(foo).toBeFalsy()
expectTypeOf(foo).toBeFalsy()
```

1 change: 0 additions & 1 deletion docs/rules/prefer-to-be-object.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using toBeObject() (`vitest/prefer-to-be-object`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-to-be-truthy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using `toBeTruthy` (`vitest/prefer-to-be-truthy`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
6 changes: 2 additions & 4 deletions docs/rules/prefer-to-be.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Enforce using toBe() (`vitest/prefer-to-be`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

### Correct
### Correct

```ts
import { test } from 'vitest'
Expand All @@ -16,7 +15,7 @@ test('foo', () => {
})
```

### Incorrect
### Incorrect

```ts
import { test } from 'vitest'
Expand All @@ -25,4 +24,3 @@ test('foo', () => {
expect(1).toEqual(1)
})
```

1 change: 0 additions & 1 deletion docs/rules/prefer-to-contain.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using toContain() (`vitest/prefer-to-contain`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-to-have-length.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using toHaveLength() (`vitest/prefer-to-have-length`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-todo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Enforce using `test.todo` (`vitest/prefer-todo`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
1 change: 0 additions & 1 deletion docs/rules/prefer-vi-mocked.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Prefer `vi.mocked()` over `fn as Mock` (`vitest/prefer-vi-mocked`)

⚠️ This rule _warns_ in the 🌐 `all` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
3 changes: 1 addition & 2 deletions docs/rules/require-hook.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Require setup and teardown to be within a hook (`vitest/require-hook`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

It's common when writing tests to need to perform a particular setup work before and after a test suite run. Because Vitest executes all `describe` handlers in a test file _before_ it executes any of the actual tests, it's important to ensure setup and teardown work is done inside `before*` and `after*` handlers respectively, rather than inside the `describe` blocks.

## Details
## Details

This rule flags any expression that is either at the toplevel of a test file or directly within the body of a `describe` except the following:

Expand Down
1 change: 0 additions & 1 deletion docs/rules/require-to-throw-message.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Require toThrow() to be called with an error message (`vitest/require-to-throw-message`)

⚠️ This rule _warns_ in the 🌐 `all` config.

<!-- end auto-generated rule header -->

Expand Down
Loading