basant307/AI_Governance_Project
048
1## eslint-plugin-vitest2 34[](https://github.com/veritem/eslint-plugin-vitest/actions/workflows/ci.yml)5 6ESLint plugin for Vitest7 8### Installation9 10You'll first need to install [ESLint](https://eslint.org/):11 12```sh13npm i eslint --save-dev14```15 16Next, install `@vitest/eslint-plugin`17 18```sh19npm install @vitest/eslint-plugin --save-dev20```21 22### Usage23 24Make sure you're running ESLint `v9.0.0` or higher for the latest version of this plugin to work. The following example is how your `eslint.config.js` should be setup for this plugin to work for you.25 26```js27import vitest from '@vitest/eslint-plugin'28 29export default [30 {31 files: ['tests/**'], // or any other pattern32 plugins: {33 vitest,34 },35 rules: {36 ...vitest.configs.recommended.rules, // you can also use vitest.configs.all.rules to enable all rules37 'vitest/max-nested-describe': ['error', { max: 3 }], // you can also modify rules' behavior using option like this38 },39 },40]41```42 43If you're not using the latest version of ESLint (version `v8.57.0` or lower) you can setup this plugin using the following configuration44 45Add `vitest` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:46 47```json48{49 "plugins": ["@vitest"]50}51```52 53Then configure the rules you want to use under the rules section.54 55```json56{57 "rules": {58 "@vitest/max-nested-describe": [59 "error",60 {61 "max": 362 }63 ]64 }65}66```67 68If you're using old ESLint configuration, make sure to use legacy key like the following69 70```js71{72 "extends": ["plugin:@vitest/legacy-recommended"] // or legacy-all73}74```75 76#### Enabling with type-testing77 78Vitest ships with an optional [type-testing feature](https://vitest.dev/guide/testing-types), which is disabled by default.79 80If you're using this feature, you should also enabled `typecheck` in the settings for this plugin. This ensures that rules like [expect-expect](docs/rules/expect-expect.md) account for type-related assertions in tests.81 82```js83import vitest from '@vitest/eslint-plugin'84 85export default [86 {87 files: ['tests/**'], // or any other pattern88 plugins: {89 vitest,90 },91 rules: {92 ...vitest.configs.recommended.rules,93 },94 settings: {95 vitest: {96 typecheck: true,97 },98 },99 languageOptions: {100 globals: {101 ...vitest.environments.env.globals,102 },103 },104 },105]106```107 108### Shareable configurations109 110#### Recommended111 112This plugin exports a recommended configuration that enforces good testing practices.113 114To enable this configuration with `eslint.config.js`, use `vitest.configs.recommended`:115 116```js117import vitest from '@vitest/eslint-plugin'118 119export default [120 {121 files: ['tests/**'], // or any other pattern122 ...vitest.configs.recommended,123 },124]125```126 127#### All128 129If you want to enable all rules instead of only some you can do so by adding the all configuration to your `eslint.config.js` config file:130 131```js132import vitest from '@vitest/eslint-plugin'133 134export default [135 {136 files: ['tests/**'], // or any other pattern137 ...vitest.configs.all,138 },139]140```141 142### Rules143 144<!-- begin auto-generated rules list -->145 146πΌ Configurations enabled in.\147β οΈ Configurations set to warn in.\148π« Configurations disabled in.\149π Set in the `all` configuration.\150β
Set in the `recommended` configuration.\151π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\152π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\153π Requires [type information](https://typescript-eslint.io/linting/typed-linting).\154β Deprecated.155 156| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |157| :----------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- | :-- | :-- | :-- | :-- | :-- | :-- | :-- |158| [consistent-test-filename](docs/rules/consistent-test-filename.md) | require .spec test file pattern | | π | | | | | |159| [consistent-test-it](docs/rules/consistent-test-it.md) | enforce using test or it but not both | | π | | π§ | | | |160| [consistent-vitest-vi](docs/rules/consistent-vitest-vi.md) | enforce using vitest or vi but not both | | π | | π§ | | | |161| [expect-expect](docs/rules/expect-expect.md) | enforce having expectation in test body | β
| π | | | | | |162| [max-expects](docs/rules/max-expects.md) | enforce a maximum number of expect per test | | π | | | | | |163| [max-nested-describe](docs/rules/max-nested-describe.md) | require describe block to be less than set max value or default value | | π | | | | | |164| [no-alias-methods](docs/rules/no-alias-methods.md) | disallow alias methods | | π | | π§ | | | |165| [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | disallow commented out tests | β
| π | | | | | |166| [no-conditional-expect](docs/rules/no-conditional-expect.md) | disallow conditional expects | | π | | | | | |167| [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | disallow conditional tests | | π | | | | | |168| [no-conditional-tests](docs/rules/no-conditional-tests.md) | disallow conditional tests | | π | | | | | |169| [no-disabled-tests](docs/rules/no-disabled-tests.md) | disallow disabled tests | | π | | | | | |170| [no-done-callback](docs/rules/no-done-callback.md) | disallow using a callback in asynchronous tests and hooks | | π | | | π‘ | | β |171| [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | disallow duplicate hooks and teardown hooks | | π | | | | | |172| [no-focused-tests](docs/rules/no-focused-tests.md) | disallow focused tests | | π | | π§ | | | |173| [no-hooks](docs/rules/no-hooks.md) | disallow setup and teardown hooks | | π | | | | | |174| [no-identical-title](docs/rules/no-identical-title.md) | disallow identical titles | β
| π | | π§ | | | |175| [no-import-node-test](docs/rules/no-import-node-test.md) | disallow importing `node:test` | β
| π | | π§ | | | |176| [no-importing-vitest-globals](docs/rules/no-importing-vitest-globals.md) | disallow importing Vitest globals | | | π | π§ | | | |177| [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | disallow string interpolation in snapshots | | π | | π§ | | | |178| [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | π | | | | | |179| [no-mocks-import](docs/rules/no-mocks-import.md) | disallow importing from **mocks** directory | | π | | | | | |180| [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | disallow the use of certain matchers | | π | | | | | |181| [no-restricted-vi-methods](docs/rules/no-restricted-vi-methods.md) | disallow specific `vi.` methods | | π | | | | | |182| [no-standalone-expect](docs/rules/no-standalone-expect.md) | disallow using `expect` outside of `it` or `test` blocks | | π | | | | | |183| [no-test-prefixes](docs/rules/no-test-prefixes.md) | disallow using the `f` and `x` prefixes in favour of `.only` and `.skip` | | π | | π§ | | | |184| [no-test-return-statement](docs/rules/no-test-return-statement.md) | disallow return statements in tests | | π | | | | | |185| [padding-around-after-all-blocks](docs/rules/padding-around-after-all-blocks.md) | Enforce padding around `afterAll` blocks | | π | | π§ | | | |186| [padding-around-after-each-blocks](docs/rules/padding-around-after-each-blocks.md) | Enforce padding around `afterEach` blocks | | π | | π§ | | | |187| [padding-around-all](docs/rules/padding-around-all.md) | Enforce padding around vitest functions | | π | | π§ | | | |188| [padding-around-before-all-blocks](docs/rules/padding-around-before-all-blocks.md) | Enforce padding around `beforeAll` blocks | | π | | π§ | | | |189| [padding-around-before-each-blocks](docs/rules/padding-around-before-each-blocks.md) | Enforce padding around `beforeEach` blocks | | π | | π§ | | | |190| [padding-around-describe-blocks](docs/rules/padding-around-describe-blocks.md) | Enforce padding around `describe` blocks | | π | | π§ | | | |191| [padding-around-expect-groups](docs/rules/padding-around-expect-groups.md) | Enforce padding around `expect` groups | | π | | π§ | | | |192| [padding-around-test-blocks](docs/rules/padding-around-test-blocks.md) | Enforce padding around `test` blocks | | π | | π§ | | | |193| [prefer-called-once](docs/rules/prefer-called-once.md) | enforce using `toBeCalledOnce()` or `toHaveBeenCalledOnce()` | | π | | π§ | | | |194| [prefer-called-times](docs/rules/prefer-called-times.md) | enforce using `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` | | π | | π§ | | | |195| [prefer-called-with](docs/rules/prefer-called-with.md) | enforce using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | π | | π§ | | | |196| [prefer-comparison-matcher](docs/rules/prefer-comparison-matcher.md) | enforce using the built-in comparison matchers | | π | | π§ | | | |197| [prefer-describe-function-title](docs/rules/prefer-describe-function-title.md) | enforce using a function as a describe title over an equivalent string | | π | | π§ | | | |198| [prefer-each](docs/rules/prefer-each.md) | enforce using `each` rather than manual loops | | π | | | | | |199| [prefer-equality-matcher](docs/rules/prefer-equality-matcher.md) | enforce using the built-in quality matchers | | π | | | π‘ | | |200| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | enforce using expect assertions instead of callbacks | | π | | | π‘ | | |201| [prefer-expect-resolves](docs/rules/prefer-expect-resolves.md) | enforce using `expect().resolves` over `expect(await ...)` syntax | | π | | π§ | | | |202| [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | enforce having hooks in consistent order | | π | | | | | |203| [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | enforce having hooks before any test cases | | π | | | | | |204| [prefer-importing-vitest-globals](docs/rules/prefer-importing-vitest-globals.md) | enforce importing Vitest globals | | π | | π§ | | | |205| [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | enforce lowercase titles | | π | | π§ | | | |206| [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | enforce mock resolved/rejected shorthands for promises | | π | | π§ | | | |207| [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | enforce including a hint with external snapshots | | π | | | | | |208| [prefer-spy-on](docs/rules/prefer-spy-on.md) | enforce using `vi.spyOn` | | π | | π§ | | | |209| [prefer-strict-boolean-matchers](docs/rules/prefer-strict-boolean-matchers.md) | enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean | | π | | π§ | | | |210| [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | enforce strict equal over equal | | π | | | π‘ | | |211| [prefer-to-be](docs/rules/prefer-to-be.md) | enforce using toBe() | | π | | π§ | | | |212| [prefer-to-be-falsy](docs/rules/prefer-to-be-falsy.md) | enforce using toBeFalsy() | | | π | π§ | | | |213| [prefer-to-be-object](docs/rules/prefer-to-be-object.md) | enforce using toBeObject() | | π | | π§ | | | |214| [prefer-to-be-truthy](docs/rules/prefer-to-be-truthy.md) | enforce using `toBeTruthy` | | | π | π§ | | | |215| [prefer-to-contain](docs/rules/prefer-to-contain.md) | enforce using toContain() | | π | | π§ | | | |216| [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | enforce using toHaveLength() | | π | | π§ | | | |217| [prefer-todo](docs/rules/prefer-todo.md) | enforce using `test.todo` | | π | | π§ | | | |218| [prefer-vi-mocked](docs/rules/prefer-vi-mocked.md) | require `vi.mocked()` over `fn as Mock` | | π | | π§ | | π | |219| [require-hook](docs/rules/require-hook.md) | require setup and teardown to be within a hook | | π | | | | | |220| [require-local-test-context-for-concurrent-snapshots](docs/rules/require-local-test-context-for-concurrent-snapshots.md) | require local Test Context for concurrent snapshot tests | β
| π | | | | | |221| [require-mock-type-parameters](docs/rules/require-mock-type-parameters.md) | enforce using type parameters with vitest mock functions | | π | | π§ | | | |222| [require-to-throw-message](docs/rules/require-to-throw-message.md) | require toThrow() to be called with an error message | | π | | | | | |223| [require-top-level-describe](docs/rules/require-top-level-describe.md) | enforce that all tests are in a top-level describe | | π | | | | | |224| [valid-describe-callback](docs/rules/valid-describe-callback.md) | enforce valid describe callback | β
| π | | | | | |225| [valid-expect](docs/rules/valid-expect.md) | enforce valid `expect()` usage | β
| π | | π§ | | | |226| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | require promises that have expectations in their chain to be valid | | π | | | | | |227| [valid-title](docs/rules/valid-title.md) | enforce valid titles | β
| π | | π§ | | | |228| [warn-todo](docs/rules/warn-todo.md) | disallow `.todo` usage | | | | | | | |229 230<!-- end auto-generated rules list -->231 232#### Credits233 234- [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest):235 most of the rules in this plugin are essentially ports of Jest plugin rules with minor modifications236 237### Licence238 239[MIT](https://github.com/veritem/eslint-plugin-vitest/blob/main/LICENSE) Licence © 2022 - present [veritem](https://github.com/veritem) and contributors240 