1.1.20 β€’ Published 3 days ago

@vitest/eslint-plugin v1.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

eslint-plugin-vitest

npm ci

ESLint plugin for Vitest

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install @vitest/eslint-plugin

npm install @vitest/eslint-plugin --save-dev

Usage

Make 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.

import vitest from "@vitest/eslint-plugin";

export default [
  {
    files: ["tests/**"], // or any other pattern
    plugins: {
      vitest
    },
    rules: {
      ...vitest.configs.recommended.rules, // you can also use vitest.configs.all.rules to enable all rules
      "vitest/max-nested-describe": ["error", { "max": 3 }] // you can also modify rules' behavior using option like this
    },
  },
];

If you're not using the latest version of ESLint (version v8.57.0 or lower) you can setup this plugin using the following configuration

Add vitest to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["@vitest"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "vitest/max-nested-describe": [
      "error",
      {
        "max": 3
      }
    ]
  }
}

If you're using old ESLint configuration, make sure to use legacy key like the following

{
  "extends": ["plugin:@vitest/legacy-recommended"] // or legacy-all
}

Enabling with type-testing

Vitest ships with an optional type-testing feature, which is disabled by default.

If you're using this feature, you should also enabled typecheck in the settings for this plugin. This ensures that rules like expect-expect account for type-related assertions in tests.

import vitest from "@vitest/eslint-plugin";

export default [
  {
    files: ["tests/**"], // or any other pattern
    plugins: {
      vitest,
    },
    rules: {
      ...vitest.configs.recommended.rules,
    },
   settings: {
      vitest: {
        typecheck: true
      }
    },
    languageOptions: {
      globals: {
        ...vitest.environments.env.globals,
      },
    },
  },
]

Shareable configurations

Recommended

This plugin exports a recommended configuration that enforces good testing practices.

To enable this configuration with eslint.config.js, use vitest.configs.recommended:

import vitest from "@vitest/eslint-plugin";

export default [
  {
    files: ["tests/**"], // or any other pattern
     ...vitest.configs.recommended,
  }
]

All

If 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:

import vitest from "@vitest/eslint-plugin";

export default [
  {
    files: ["tests/**"], // or any other pattern
     ...vitest.configs.all,
  }
]

Rules

πŸ’Ό Configurations enabled in.\ ⚠️ Configurations set to warn in.\ 🌐 Set in the all configuration.\ βœ… Set in the recommended configuration.\ πŸ”§ Automatically fixable by the --fix CLI option.\ πŸ’‘ Manually fixable by editor suggestions.\ ❌ Deprecated.

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β DescriptionπŸ’Όβš οΈπŸ”§πŸ’‘βŒ
consistent-test-filenamerequire .spec test file pattern🌐
consistent-test-itenforce using test or it but not bothπŸŒπŸ”§
expect-expectenforce having expectation in test bodyβœ…πŸŒ
max-expectsenforce a maximum number of expect per test🌐
max-nested-describerequire describe block to be less than set max value or default value🌐
no-alias-methodsdisallow alias methodsπŸŒπŸ”§
no-commented-out-testsdisallow commented out testsβœ…πŸŒ
no-conditional-expectdisallow conditional expects🌐
no-conditional-in-testdisallow conditional tests🌐
no-conditional-testsdisallow conditional tests🌐
no-disabled-testsdisallow disabled tests🌐
no-done-callbackdisallow using a callback in asynchronous tests and hooksπŸŒπŸ’‘βŒ
no-duplicate-hooksdisallow duplicate hooks and teardown hooks🌐
no-focused-testsdisallow focused testsπŸŒπŸ”§
no-hooksdisallow setup and teardown hooks🌐
no-identical-titledisallow identical titlesβœ…πŸŒπŸ”§
no-import-node-testdisallow importing node:testβœ…πŸŒπŸ”§
no-interpolation-in-snapshotsdisallow string interpolation in snapshotsπŸŒπŸ”§
no-large-snapshotsdisallow large snapshots🌐
no-mocks-importdisallow importing from mocks directory🌐
no-restricted-matchersdisallow the use of certain matchers🌐
no-restricted-vi-methodsdisallow specific vi. methods🌐
no-standalone-expectdisallow using expect outside of it or test blocks🌐
no-test-prefixesdisallow using test as a prefixπŸŒπŸ”§
no-test-return-statementdisallow return statements in tests🌐
prefer-called-withenforce using toBeCalledWith() or toHaveBeenCalledWith()πŸŒπŸ”§
prefer-comparison-matcherenforce using the built-in comparison matchersπŸŒπŸ”§
prefer-eachenforce using each rather than manual loops🌐
prefer-equality-matcherenforce using the built-in quality matchersπŸŒπŸ’‘
prefer-expect-assertionsenforce using expect assertions instead of callbacksπŸŒπŸ’‘
prefer-expect-resolvesenforce using expect().resolves over expect(await ...) syntaxπŸŒπŸ”§
prefer-hooks-in-orderenforce having hooks in consistent order🌐
prefer-hooks-on-topenforce having hooks before any test cases🌐
prefer-lowercase-titleenforce lowercase titlesπŸŒπŸ”§
prefer-mock-promise-shorthandenforce mock resolved/rejected shorthands for promisesπŸŒπŸ”§
prefer-snapshot-hintenforce including a hint with external snapshots🌐
prefer-spy-onenforce using vi.spyOnπŸŒπŸ”§
prefer-strict-equalenforce strict equal over equalπŸŒπŸ’‘
prefer-to-beenforce using toBe()πŸŒπŸ”§
prefer-to-be-falsyenforce using toBeFalsy()πŸŒπŸ”§
prefer-to-be-objectenforce using toBeObject()πŸŒπŸ”§
prefer-to-be-truthyenforce using toBeTruthyπŸŒπŸ”§
prefer-to-containenforce using toContain()πŸŒπŸ”§
prefer-to-have-lengthenforce using toHaveLength()πŸŒπŸ”§
prefer-todoenforce using test.todoπŸŒπŸ”§
prefer-vi-mockedPrefer vi.mocked() over fn as MockπŸŒπŸ”§
require-hookrequire setup and teardown to be within a hook🌐
require-local-test-context-for-concurrent-snapshotsrequire local Test Context for concurrent snapshot testsβœ…πŸŒ
require-to-throw-messagerequire toThrow() to be called with an error message🌐
require-top-level-describeenforce that all tests are in a top-level describe🌐
valid-describe-callbackenforce valid describe callbackβœ…πŸŒ
valid-expectenforce valid expect() usageβœ…πŸŒπŸ”§
valid-titleenforce valid titlesβœ…πŸŒπŸ”§
valid-expect-in-promiserequire promises that have expectations in their chain to be valid🌐

Credits

  • eslint-plugin-jest Most of the rules in this plugin are essentially ports of Jest plugin rules with minor modifications

Licence

MIT Licence Β© 2022 - present veritem and contributors

typescript-eslint-standard@arabasta/eslint-config@antfu/eslint-config@akrc/eslint-config@cany748/eslint-config@cclr/eslint-config-common@chance/eslint@2bad/axiom@2030/eslint-config@adbayb/stack@aarongoldenthal/eslint-config-standard@coderwyd/eslint-config@bernankez/eslint-config@dhzh/eslint-config@flowr/eslint-config@elora-cloud/eslint-config@estjs/eslint-config@gilbarbara/eslint-config@ktam/lint-node@kouts/eslint-config@kriszu/eslint-config@lemonbot.fun/eslint-config@lehoczky/eslint-config-vitest@iqrf/eslint-config@ithinkdt/lint@lincy/eslint-config@luxass/eslint-config@mgcrea/eslint-config-node@mgcrea/eslint-config-react@mutoe/eslint-config@neosjs/eslint-config@nerdfish/config@nhcarrigan/eslint-config@nirtamir2/eslint-config@nodecfdi/eslint-config@epic-web/config@exer7um/eslint-config@faergeek/eslint-config@mcous/eslint-config@keksiqc/eslint-config@jiangweiye/eslint-config@ivanmaxlogiudice/eslint-config@jaypie/eslint@kodehort/eslint-config@kirklin/eslint-config@jsse/eslint-config@imyangyong/eslint-config@jhqn/eslint-config@hyperse/eslint-config-hyperse@pplancq/eslint-config@re-taro/eslint-config@rainbowatcher/eslint-config-js@open-xchange/linter-presets@ntnyq/eslint-config@nyxb/eslint-config@oat-sa/eslint-config-tao@pandell/eslint-config@ourongxing/eslint-config@pengzhanbo/eslint-config@slhs/eslint-config@slashnephy/eslint-config@sparticuz/eslint-config@tabula/eslint-config@removify/eslint-config@stacksjs/eslint-config@dorabag/eslint-config@dethdkn/eslint-config@rotki/eslint-configaberlaas-lintbundled-eslint-configeslint-config-bloqeslint-config-chanceeslint-config-archisquadeslint-config-sheriffeslint-config-shinyeslint-config-thewlabseslint-config-tidaleslint-config-gmanaeslint-config-lostfictionseslint-config-molindoeslint-config-mister-hopeeslint-config-prosteeslint-config-reearth@toruslabs/eslint-config-typescript@tools-aoeur/eslint-config@unshared/eslint-config@vinicunca/eslint-config@wesp-up/eslint-config@wisemen/eslint-config-vue@wkovacs64/eslint-config@wiz-develop/eslint-config@wangyjhh/eslint-config@wakamsha/eslint-config@xiaohe01/eslint-config@youcan/lint@xwbx/eslint-config@zhangwj0520/eslint-config
1.1.19

3 days ago

1.1.18

5 days ago

1.1.17

5 days ago

1.1.20

3 days ago

1.1.16

11 days ago

1.1.15

12 days ago

1.1.14

20 days ago

1.1.12

25 days ago

1.1.11

26 days ago

1.1.13

21 days ago

1.1.9

1 month ago

1.1.10

1 month ago

1.1.8

1 month ago

1.1.7

3 months ago

1.1.6

3 months ago

1.1.5

3 months ago

1.1.1

3 months ago

1.1.0

4 months ago

1.1.4

3 months ago

1.0.5

4 months ago

1.1.3

3 months ago

1.0.4

4 months ago

1.1.2

3 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago

0.0.0-0

4 months ago