Socket
Socket
Sign inDemoInstall

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


Version published
Weekly downloads
614K
increased by5.25%
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

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

To use the recommended configuration, extend it in your .eslintrc file:

{
  "extends": ["plugin:vitest/recommended"]
}

All recommend rules will be set to error by default. You can however disable some rules by setting turning them off in your .eslintrc file or by setting them to warn in your .eslintrc.

all

To use the all configuration, extend it in your .eslintrc file:

{
  "extends": ["plugin:vitest/all"]
}
Running on test files only

This plugin assumes that you're running it on tests files only by default which sometimes is not the case. If you can to run it on test files only. Your configuration will look like this:

If you're using .eslintrc

{
	"extends": ["eslint:recommended"],
	"overrides": [
		{
			"files": ["tests/**"], // or any other pattern
			"plugins": ["vitest"],
			"extends": ["plugin:vitest/recommended"]
		}
	]
}

If you're using .eslintrc.js

import vitest from "eslint-plugin-vitest";

export default [
  {
    files: ["tests/**"], // or any other pattern
    plugins: {
      vitest,
    },
    rules: {
      ...vitest.configs.recommended.rules,
    },
    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.

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β DescriptionπŸ’Όβš οΈπŸ”§πŸ’‘
consistent-test-filenameforbidden .spec test file pattern🌐
consistent-test-itPrefer test or it but not bothπŸŒπŸ”§
expect-expectEnforce having expectation in test bodyβœ…
max-expectsEnforce a maximum number of expect per test🌐
max-nested-describeNested describe block should 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-withSuggest using toBeCalledWith() or toHaveBeenCalledWith()πŸŒπŸ”§
prefer-comparison-matcherSuggest using the built-in comparison matchersπŸŒπŸ”§
prefer-eachPrefer each rather than manual loops🌐
prefer-equality-matcherSuggest using the built-in quality matchersπŸŒπŸ’‘
prefer-expect-resolvesSuggest using expect().resolves over expect(await ...) syntaxπŸŒπŸ”§
prefer-hooks-in-orderPrefer having hooks in consistent order🌐
prefer-hooks-on-topSuggest having hooks before any test cases🌐
prefer-lowercase-titleEnforce lowercase titlesπŸŒπŸ”§
prefer-mock-promise-shorthandPrefer mock resolved/rejected shorthands for promisesπŸŒπŸ”§
prefer-snapshot-hintPrefer including a hint with external snapshots🌐
prefer-spy-onSuggest using vi.spyOnπŸŒπŸ”§
prefer-strict-equalPrefer strict equal over equalπŸŒπŸ’‘
prefer-to-beSuggest using toBe()βœ…πŸ”§
prefer-to-be-falsySuggest using toBeFalsy()πŸŒπŸ”§
prefer-to-be-objectPrefer toBeObject()πŸŒπŸ”§
prefer-to-be-truthySuggest using toBeTruthyπŸŒπŸ”§
prefer-to-containPrefer using toContain()πŸŒπŸ”§
prefer-to-have-lengthSuggest using toHaveLength()πŸŒπŸ”§
prefer-todoSuggest 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 11 Dec 2023

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