Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More β†’
Socket
Book a DemoInstallSign in
Socket

@vitest/eslint-plugin

Package Overview
Dependencies
Maintainers
6
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/eslint-plugin

Eslint plugin for vitest

latest
Source
npmnpm
Version
1.3.16
Version published
Weekly downloads
1.8M
-2.02%
Maintainers
6
Weekly downloads
Β 
Created
Source

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

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.
🚫 Configurations disabled in.
🌐 Set in the all configuration.
βœ… Set in the recommended configuration.
πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’‘ Manually fixable by editor suggestions.
πŸ’­ Requires type information.
❌ Deprecated.

NameDescriptionπŸ’Όβš οΈπŸš«πŸ”§πŸ’‘πŸ’­βŒ
consistent-test-filenamerequire .spec test file pattern🌐
consistent-test-itenforce using test or it but not bothπŸŒπŸ”§
consistent-vitest-vienforce using vitest or vi but not bothπŸŒπŸ”§
expect-expectenforce having expectation in test bodyβœ…πŸŒ
hoisted-apis-on-topenforce hoisted APIs to be on top of the fileπŸŒπŸ’‘
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-importing-vitest-globalsdisallow importing Vitest globalsπŸŒπŸ”§
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 the f and x prefixes in favour of .only and .skipπŸŒπŸ”§
no-test-return-statementdisallow return statements in tests🌐
padding-around-after-all-blocksEnforce padding around afterAll blocksπŸŒπŸ”§
padding-around-after-each-blocksEnforce padding around afterEach blocksπŸŒπŸ”§
padding-around-allEnforce padding around vitest functionsπŸŒπŸ”§
padding-around-before-all-blocksEnforce padding around beforeAll blocksπŸŒπŸ”§
padding-around-before-each-blocksEnforce padding around beforeEach blocksπŸŒπŸ”§
padding-around-describe-blocksEnforce padding around describe blocksπŸŒπŸ”§
padding-around-expect-groupsEnforce padding around expect groupsπŸŒπŸ”§
padding-around-test-blocksEnforce padding around test blocksπŸŒπŸ”§
prefer-called-exactly-once-withPrefer toHaveBeenCalledExactlyOnceWith over toHaveBeenCalledOnce and toHaveBeenCalledWithβœ…πŸŒπŸ”§
prefer-called-onceenforce using toBeCalledOnce() or toHaveBeenCalledOnce()πŸŒπŸ”§
prefer-called-timesenforce using toBeCalledTimes(1) or toHaveBeenCalledTimes(1)πŸŒπŸ”§
prefer-called-withenforce using toBeCalledWith() or toHaveBeenCalledWith()πŸŒπŸ”§
prefer-comparison-matcherenforce using the built-in comparison matchersπŸŒπŸ”§
prefer-describe-function-titleenforce using a function as a describe title over an equivalent stringπŸŒπŸ”§
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-expect-type-ofenforce using expectTypeOf instead of expect(typeof ...)πŸŒπŸ”§
prefer-hooks-in-orderenforce having hooks in consistent order🌐
prefer-hooks-on-topenforce having hooks before any test cases🌐
prefer-importing-vitest-globalsenforce importing Vitest globalsπŸŒπŸ”§
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-boolean-matchersenforce using toBe(true) and toBe(false) over matchers that coerce types to booleanπŸŒπŸ”§
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-mockedrequire 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-mock-type-parametersenforce using type parameters with vitest mock functionsπŸŒπŸ”§
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-expect-in-promiserequire promises that have expectations in their chain to be valid🌐
valid-titleenforce valid titlesβœ…πŸŒπŸ”§
warn-tododisallow .todo usage
prefer-import-in-mocenforce dynamic import in mockβœ…πŸŒπŸ”§

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

Keywords

eslint

FAQs

Package last updated on 05 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts