Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

eslint-plugin-vitest

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-vitest

Eslint plugin for vitest

  • 0.5.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
559K
increased by5.65%
Maintainers
1
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 eslint-plugin-vitest:

npm install eslint-plugin-vitest --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 "eslint-plugin-vitest";

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
      }
    ]
  }
}
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 "eslint-plugin-vitest";

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,
      },
    },
  },
]

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πŸŒπŸ”§
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βœ…πŸ”§
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

Keywords

FAQs

Package last updated on 23 Apr 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc