diff --git a/README.md b/README.md index 3a50417..81ffdbc 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ All peer dependencies used by `@code-pushup/eslint-config` are listed below, alo | ![typescript](./docs/icons/material/typescript.png) | [typescript-eslint](https://www.npmjs.com/package/typescript-eslint) | `^8.0.0` | โœ… | | ![graphql](./docs/icons/material/graphql.png) | [@graphql-eslint/eslint-plugin](https://www.npmjs.com/package/@graphql-eslint/eslint-plugin) | `^3.0.0` | | | ![ngrx](./docs/icons/other/ngrx.png) | [@ngrx/eslint-plugin](https://www.npmjs.com/package/@ngrx/eslint-plugin) | `^18.0.0 \|\| ^19.0.0` | | +| ![vitest](./docs/icons/material/vitest.png) | [@vitest/eslint-plugin](https://www.npmjs.com/package/@vitest/eslint-plugin) | `^1.0.0` | | | ![angular](./docs/icons/material/angular.png) | [angular-eslint](https://www.npmjs.com/package/angular-eslint) | `^18.0.0 \|\| ^19.0.0` | | | ![cypress](./docs/icons/material/cypress.png) | [eslint-plugin-cypress](https://www.npmjs.com/package/eslint-plugin-cypress) | `>=3.3.0` | | | ![jest](./docs/icons/material/jest.png) | [eslint-plugin-jest](https://www.npmjs.com/package/eslint-plugin-jest) | `^28.8.0` | | @@ -94,7 +95,6 @@ All peer dependencies used by `@code-pushup/eslint-config` are listed below, alo | ![rxjs](./docs/icons/other/rxjs.png) | [eslint-plugin-rxjs-x](https://www.npmjs.com/package/eslint-plugin-rxjs-x) | `>=0.6.0` | | | ![storybook](./docs/icons/material/storybook.png) | [eslint-plugin-storybook](https://www.npmjs.com/package/eslint-plugin-storybook) | `>=0.10.0` | | | ![testing-library](./docs/icons/other/testing-library.png) | [eslint-plugin-testing-library](https://www.npmjs.com/package/eslint-plugin-testing-library) | `^7.1.1` | | -| ![vitest](./docs/icons/material/vitest.png) | [eslint-plugin-vitest](https://www.npmjs.com/package/eslint-plugin-vitest) | `>=0.5.0` | | ### ๐Ÿงช Test overrides diff --git a/docs/vitest.md b/docs/vitest.md index 10147b6..4f4e4b3 100644 --- a/docs/vitest.md +++ b/docs/vitest.md @@ -8,7 +8,7 @@ Config for projects using **Vitest** for testing. 2. Since this plugin requires additional peer dependencies, you have to install them as well: ```sh - npm install -D eslint-plugin-{jest-formatting,vitest} + npm install -D @vitest/eslint-plugin ``` 3. Add to your `eslint.config.js` file: @@ -34,57 +34,61 @@ Config for projects using **Vitest** for testing. ); ``` -## ๐Ÿ“ Rules (41) +## ๐Ÿ“ Rules (45) > ๐Ÿ”ง Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
๐Ÿ’ก Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). -### ๐Ÿšจ Errors (8) +### ๐Ÿšจ Errors (9) -| Plugin | Rule | Options | Autofix | Overrides | -| :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :-----: | :-------: | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [expect-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/expect-expect.md)
enforce having expectation in test body | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-commented-out-tests](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-commented-out-tests.md)
disallow commented out tests | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-identical-title](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-identical-title.md)
disallow identical titles | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-import-node-test](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-import-node-test.md)
disallow importing `node:test` | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-local-test-context-for-concurrent-snapshots](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/require-local-test-context-for-concurrent-snapshots.md)
require local Test Context for concurrent snapshot tests | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-describe-callback](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/valid-describe-callback.md)
enforce valid describe callback | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/valid-expect.md)
enforce valid `expect()` usage | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-title](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md)
enforce valid titles | | ๐Ÿ”ง | | +| Plugin | Rule | Options | Autofix | Overrides | +| :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :-----: | :-------: | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [expect-expect](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/expect-expect.md)
enforce having expectation in test body | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-commented-out-tests](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-commented-out-tests.md)
disallow commented out tests | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-identical-title](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-identical-title.md)
disallow identical titles | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-import-node-test](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-import-node-test.md)
disallow importing `node:test` | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-local-test-context-for-concurrent-snapshots](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/require-local-test-context-for-concurrent-snapshots.md)
require local Test Context for concurrent snapshot tests | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-describe-callback](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-describe-callback.md)
enforce valid describe callback | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-expect](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-expect.md)
enforce valid `expect()` usage | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-expect-in-promise](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-expect-in-promise.md)
require promises that have expectations in their chain to be valid | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [valid-title](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md)
enforce valid titles | | ๐Ÿ”ง | | -### โš ๏ธ Warnings (33) +### โš ๏ธ Warnings (36) -| Plugin | Rule | Options | Autofix | Overrides | -| :-------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: | :-------: | -| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-after-all-blocks
| | ๐Ÿ”ง | | -| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-after-each-blocks
| | ๐Ÿ”ง | | -| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-before-all-blocks
| | ๐Ÿ”ง | | -| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-before-each-blocks
| | ๐Ÿ”ง | | -| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-describe-blocks
| | ๐Ÿ”ง | | -| [![jest-formatting](./icons/icons8/test.png)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting#readme) | padding-around-test-blocks
| | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [consistent-test-filename](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md)
require .spec test file pattern |
pattern: .\*\\.spec\\.[tj]sx?$
{
  "pattern": ".\*\\\\.spec\\\\.[tj]sx?$"
}
| | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [consistent-test-it](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-it.md)
enforce using test or it but not both | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [max-nested-describe](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/max-nested-describe.md)
require describe block to be less than set max value or default value |
max: 2
{
  "max": 2
}
| | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-alias-methods](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-alias-methods.md)
disallow alias methods | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-conditional-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-expect.md)
disallow conditional expects | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-conditional-tests](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-tests.md)
disallow conditional tests | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-disabled-tests](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-disabled-tests.md)
disallow disabled tests | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-done-callback](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-done-callback.md)
disallow using a callback in asynchronous tests and hooks | | ๐Ÿ’ก | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-duplicate-hooks](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-duplicate-hooks.md)
disallow duplicate hooks and teardown hooks | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-focused-tests](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-focused-tests.md)
disallow focused tests | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-mocks-import](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-mocks-import.md)
disallow importing from __mocks__ directory | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-standalone-expect](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-standalone-expect.md)
disallow using `expect` outside of `it` or `test` blocks | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-test-return-statement](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-test-return-statement.md)
disallow return statements in tests | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-comparison-matcher](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-comparison-matcher.md)
enforce using the built-in comparison matchers | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-each](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-each.md)
enforce using `each` rather than manual loops | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-equality-matcher](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-equality-matcher.md)
enforce using the built-in quality matchers | | ๐Ÿ’ก | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-expect-resolves](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-expect-resolves.md)
enforce using `expect().resolves` over `expect(await ...)` syntax | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-hooks-on-top](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-hooks-on-top.md)
enforce having hooks before any test cases | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-mock-promise-shorthand](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-mock-promise-shorthand.md)
enforce mock resolved/rejected shorthands for promises | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-spy-on](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-spy-on.md)
enforce using `vi.spyOn` | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-to-be](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-be.md)
enforce using toBe() | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-to-contain](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-contain.md)
enforce using toContain() | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-to-have-length](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-have-length.md)
enforce using toHaveLength() | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-todo](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/prefer-todo.md)
enforce using `test.todo` | | ๐Ÿ”ง | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-hook](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/require-hook.md)
require setup and teardown to be within a hook | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-to-throw-message](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/require-to-throw-message.md)
require toThrow() to be called with an error message | | | | -| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-top-level-describe](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/require-top-level-describe.md)
enforce that all tests are in a top-level describe | | | | +| Plugin | Rule | Options | Autofix | Overrides | +| :----------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: | :-------: | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [consistent-test-filename](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-filename.md)
require .spec test file pattern |
pattern: .\*\\.spec\\.[tj]sx?$
{
  "pattern": ".\*\\\\.spec\\\\.[tj]sx?$"
}
| | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [consistent-test-it](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/consistent-test-it.md)
enforce using test or it but not both | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [max-nested-describe](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/max-nested-describe.md)
require describe block to be less than set max value or default value |
max: 2
{
  "max": 2
}
| | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-alias-methods](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-alias-methods.md)
disallow alias methods | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-conditional-expect](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-expect.md)
disallow conditional expects | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-conditional-tests](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-tests.md)
disallow conditional tests | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-disabled-tests](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-disabled-tests.md)
disallow disabled tests | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-done-callback](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-done-callback.md)
disallow using a callback in asynchronous tests and hooks | | ๐Ÿ’ก | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-duplicate-hooks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-duplicate-hooks.md)
disallow duplicate hooks and teardown hooks | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-focused-tests](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-focused-tests.md)
disallow focused tests | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-mocks-import](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-mocks-import.md)
disallow importing from __mocks__ directory | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-standalone-expect](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-standalone-expect.md)
disallow using `expect` outside of `it` or `test` blocks | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [no-test-return-statement](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-test-return-statement.md)
disallow return statements in tests | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [padding-around-after-all-blocks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-after-all-blocks.md)
Enforce padding around `afterAll` blocks | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [padding-around-after-each-blocks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-after-each-blocks.md)
Enforce padding around `afterEach` blocks | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [padding-around-before-all-blocks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-before-all-blocks.md)
Enforce padding around `beforeAll` blocks | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [padding-around-before-each-blocks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-before-each-blocks.md)
Enforce padding around `beforeEach` blocks | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [padding-around-describe-blocks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-describe-blocks.md)
Enforce padding around `describe` blocks | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [padding-around-test-blocks](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-test-blocks.md)
Enforce padding around `test` blocks | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-comparison-matcher](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-comparison-matcher.md)
enforce using the built-in comparison matchers | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-each](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-each.md)
enforce using `each` rather than manual loops | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-equality-matcher](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-equality-matcher.md)
enforce using the built-in quality matchers | | ๐Ÿ’ก | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-expect-resolves](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-expect-resolves.md)
enforce using `expect().resolves` over `expect(await ...)` syntax | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-hooks-on-top](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-hooks-on-top.md)
enforce having hooks before any test cases | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-mock-promise-shorthand](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-mock-promise-shorthand.md)
enforce mock resolved/rejected shorthands for promises | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-spy-on](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-spy-on.md)
enforce using `vi.spyOn` | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-strict-boolean-matchers](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-strict-boolean-matchers.md)
enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-to-be](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-be.md)
enforce using toBe() | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-to-contain](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-contain.md)
enforce using toContain() | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-to-have-length](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-to-have-length.md)
enforce using toHaveLength() | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-todo](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-todo.md)
enforce using `test.todo` | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [prefer-vi-mocked](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-vi-mocked.md)
require `vi.mocked()` over `fn as Mock` | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-hook](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/require-hook.md)
require setup and teardown to be within a hook | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-mock-type-parameters](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/require-mock-type-parameters.md)
enforce using type parameters with vitest mock functions | | ๐Ÿ”ง | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-to-throw-message](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/require-to-throw-message.md)
require toThrow() to be called with an error message | | | | +| [![vitest](./icons/material/vitest.png)](https://github.com/veritem/eslint-plugin-vitest#readme) | [require-top-level-describe](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/require-top-level-describe.md)
enforce that all tests are in a top-level describe | | | | diff --git a/package-lock.json b/package-lock.json index 4028529..d81a057 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@types/eslint__js": "^8.42.3", "@typescript-eslint/types": "^8.13.0", "@vitest/coverage-v8": "^2.1.4", + "@vitest/eslint-plugin": "^1.1.31", "angular-eslint": "^19.0.2", "build-md": "^0.4.1", "compare-versions": "^6.1.0", @@ -36,7 +37,6 @@ "eslint-plugin-storybook": "^0.11.2", "eslint-plugin-testing-library": "^7.1.1", "eslint-plugin-unicorn": "^56.0.1", - "eslint-plugin-vitest": "^0.5.4", "globals": "^15.12.0", "graphql": "^16.9.0", "husky": "^8.0.0", @@ -50,6 +50,7 @@ "@eslint/js": "^9.0.0", "@graphql-eslint/eslint-plugin": "^3.0.0", "@ngrx/eslint-plugin": "^18.0.0 || ^19.0.0", + "@vitest/eslint-plugin": "^1.0.0", "angular-eslint": "^18.0.0 || ^19.0.0", "eslint": "^9.0.0", "eslint-import-resolver-typescript": "^3.0.0", @@ -69,7 +70,6 @@ "eslint-plugin-storybook": ">=0.10.0", "eslint-plugin-testing-library": "^7.1.1", "eslint-plugin-unicorn": ">=50.0.0", - "eslint-plugin-vitest": ">=0.5.0", "globals": ">=14.0.0", "typescript-eslint": "^8.0.0" }, @@ -80,6 +80,9 @@ "@ngrx/eslint-plugin": { "optional": true }, + "@vitest/eslint-plugin": { + "optional": true + }, "angular-eslint": { "optional": true }, @@ -118,9 +121,6 @@ }, "eslint-plugin-testing-library": { "optional": true - }, - "eslint-plugin-vitest": { - "optional": true } } }, @@ -2855,6 +2855,27 @@ } } }, + "node_modules/@vitest/eslint-plugin": { + "version": "1.1.31", + "resolved": "https://registry.npmjs.org/@vitest/eslint-plugin/-/eslint-plugin-1.1.31.tgz", + "integrity": "sha512-xlsLr+e+AXZ/00eVZCtNmMeCJoJaRCoLDiAgLcxgQjSS1EertieB2MUHf8xIqPKs9lECc/UpL+y1xDcpvi02hw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@typescript-eslint/utils": ">= 8.0", + "eslint": ">= 8.57.0", + "typescript": ">= 5.0.0", + "vitest": "*" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + }, + "vitest": { + "optional": true + } + } + }, "node_modules/@vitest/expect": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.4.tgz", @@ -5642,163 +5663,6 @@ "node": ">=10" } }, - "node_modules/eslint-plugin-vitest": { - "version": "0.5.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-vitest/-/eslint-plugin-vitest-0.5.4.tgz", - "integrity": "sha512-um+odCkccAHU53WdKAw39MY61+1x990uXjSPguUCq3VcEHdqJrOb8OTMrbYlY6f9jAKx7x98kLVlIe3RJeJqoQ==", - "dev": true, - "dependencies": { - "@typescript-eslint/utils": "^7.7.1" - }, - "engines": { - "node": "^18.0.0 || >= 20.0.0" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", - "vitest": "*" - }, - "peerDependenciesMeta": { - "@typescript-eslint/eslint-plugin": { - "optional": true - }, - "vitest": { - "optional": true - } - } - }, - "node_modules/eslint-plugin-vitest/node_modules/@typescript-eslint/scope-manager": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz", - "integrity": "sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/eslint-plugin-vitest/node_modules/@typescript-eslint/types": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.18.0.tgz", - "integrity": "sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==", - "dev": true, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/eslint-plugin-vitest/node_modules/@typescript-eslint/typescript-estree": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz", - "integrity": "sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", - "debug": "^4.3.4", - "globby": "^11.1.0", - "is-glob": "^4.0.3", - "minimatch": "^9.0.4", - "semver": "^7.6.0", - "ts-api-utils": "^1.3.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/eslint-plugin-vitest/node_modules/@typescript-eslint/utils": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.18.0.tgz", - "integrity": "sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/typescript-estree": "7.18.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - } - }, - "node_modules/eslint-plugin-vitest/node_modules/@typescript-eslint/visitor-keys": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz", - "integrity": "sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "7.18.0", - "eslint-visitor-keys": "^3.4.3" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/eslint-plugin-vitest/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/eslint-plugin-vitest/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/eslint-plugin-vitest/node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", - "dev": true, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/eslint-scope": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", diff --git a/package.json b/package.json index d8d65a8..337ae7a 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@eslint/js": "^9.0.0", "@graphql-eslint/eslint-plugin": "^3.0.0", "@ngrx/eslint-plugin": "^18.0.0 || ^19.0.0", + "@vitest/eslint-plugin": "^1.0.0", "angular-eslint": "^18.0.0 || ^19.0.0", "eslint": "^9.0.0", "eslint-import-resolver-typescript": "^3.0.0", @@ -67,7 +68,6 @@ "eslint-plugin-storybook": ">=0.10.0", "eslint-plugin-testing-library": "^7.1.1", "eslint-plugin-unicorn": ">=50.0.0", - "eslint-plugin-vitest": ">=0.5.0", "globals": ">=14.0.0", "typescript-eslint": "^8.0.0" }, @@ -78,6 +78,9 @@ "@ngrx/eslint-plugin": { "optional": true }, + "@vitest/eslint-plugin": { + "optional": true + }, "angular-eslint": { "optional": true }, @@ -116,9 +119,6 @@ }, "eslint-plugin-testing-library": { "optional": true - }, - "eslint-plugin-vitest": { - "optional": true } }, "devDependencies": { @@ -128,6 +128,7 @@ "@types/eslint__js": "^8.42.3", "@typescript-eslint/types": "^8.13.0", "@vitest/coverage-v8": "^2.1.4", + "@vitest/eslint-plugin": "^1.1.31", "angular-eslint": "^19.0.2", "build-md": "^0.4.1", "compare-versions": "^6.1.0", @@ -149,7 +150,6 @@ "eslint-plugin-storybook": "^0.11.2", "eslint-plugin-testing-library": "^7.1.1", "eslint-plugin-unicorn": "^56.0.1", - "eslint-plugin-vitest": "^0.5.4", "globals": "^15.12.0", "graphql": "^16.9.0", "husky": "^8.0.0", diff --git a/scripts/docs.js b/scripts/docs.js index 2e60410..a755b0c 100644 --- a/scripts/docs.js +++ b/scripts/docs.js @@ -75,6 +75,7 @@ async function loadPeerDependencies(configs) { return ( plugins.includes(pkg) || plugins.includes(alias) || + plugins.includes(alias.replace(/^@/, '')) || plugins.map(plugin => plugin.replace(/^@/, '')).includes(alias) ); }, diff --git a/scripts/helpers/plugins.js b/scripts/helpers/plugins.js index 3dc0db5..449537f 100644 --- a/scripts/helpers/plugins.js +++ b/scripts/helpers/plugins.js @@ -8,6 +8,7 @@ const pluginIcons = { '@ngrx': 'other/ngrx', '@rx-angular': 'other/rx-angular', '@typescript-eslint': 'material/typescript', + '@vitest': 'material/vitest', cypress: 'material/cypress', deprecation: 'icons8/expired', functional: 'icons8/lambda', @@ -40,6 +41,7 @@ const pluginDocsUrls = { '@ngrx': 'https://ngrx.io/guide/eslint-plugin', '@rx-angular': 'https://www.rx-angular.io/docs/eslint-plugin', '@typescript-eslint': 'https://typescript-eslint.io/', + '@vitest': 'https://github.com/veritem/eslint-plugin-vitest#readme', cypress: 'https://github.com/cypress-io/eslint-plugin-cypress#readme', deprecation: 'https://github.com/gund/eslint-plugin-deprecation#readme', functional: diff --git a/src/configs/vitest.js b/src/configs/vitest.js index a9e8419..cce99e0 100644 --- a/src/configs/vitest.js +++ b/src/configs/vitest.js @@ -1,10 +1,8 @@ // @ts-check -import * as jestFormatting from 'eslint-plugin-jest-formatting'; -import vitest from 'eslint-plugin-vitest'; +import vitest from '@vitest/eslint-plugin'; import tseslint from 'typescript-eslint'; import { UNIT_TEST_FILE_PATTERNS } from '../lib/patterns.js'; -import { convertErrorsToWarnings } from '../lib/utils.js'; export default tseslint.config({ files: UNIT_TEST_FILE_PATTERNS, @@ -16,15 +14,6 @@ export default tseslint.config({ globals: vitest.environments.env.globals, }, }, - { - name: 'code-pushup/vitest/jest-formatting', - plugins: { - 'jest-formatting': jestFormatting, - }, - rules: convertErrorsToWarnings( - jestFormatting.configs.recommended.overrides?.[0]?.rules, - ), - }, { name: 'code-pushup/vitest/customized', rules: { @@ -34,7 +23,7 @@ export default tseslint.config({ { name: 'code-pushup/vitest/additional', rules: { - // https://github.com/veritem/eslint-plugin-vitest#rules + // https://github.com/vitest-dev/eslint-plugin-vitest#rules 'vitest/consistent-test-filename': [ 'warn', { pattern: String.raw`.*\.spec\.[tj]sx?$` }, @@ -51,6 +40,12 @@ export default tseslint.config({ 'vitest/no-mocks-import': 'warn', 'vitest/no-standalone-expect': 'warn', 'vitest/no-test-return-statement': 'warn', + 'vitest/padding-around-after-all-blocks': 'warn', + 'vitest/padding-around-after-each-blocks': 'warn', + 'vitest/padding-around-before-all-blocks': 'warn', + 'vitest/padding-around-before-each-blocks': 'warn', + 'vitest/padding-around-describe-blocks': 'warn', + 'vitest/padding-around-test-blocks': 'warn', 'vitest/prefer-comparison-matcher': 'warn', 'vitest/prefer-each': 'warn', 'vitest/prefer-expect-resolves': 'warn', @@ -58,12 +53,28 @@ export default tseslint.config({ 'vitest/prefer-hooks-on-top': 'warn', 'vitest/prefer-mock-promise-shorthand': 'warn', 'vitest/prefer-spy-on': 'warn', + // from v1.1.26 onwards + ...('prefer-strict-boolean-matchers' in vitest.rules && { + 'vitest/prefer-strict-boolean-matchers': 'warn', + }), 'vitest/prefer-to-contain': 'warn', 'vitest/prefer-to-have-length': 'warn', 'vitest/prefer-todo': 'warn', + // from v1.1.6 onwards + ...('prefer-vi-mocked' in vitest.rules && { + 'vitest/prefer-vi-mocked': 'warn', + }), 'vitest/require-hook': 'warn', + // from v1.1.27 onwards + ...('require-mock-type-parameters' in vitest.rules && { + 'vitest/require-mock-type-parameters': 'warn', + }), 'vitest/require-to-throw-message': 'warn', 'vitest/require-top-level-describe': 'warn', + // from v1.1.9 onwards + ...('valid-expect-in-promise' in vitest.rules && { + 'vitest/valid-expect-in-promise': 'error', + }), }, }, ],