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
Maintainers
1
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,
      },
    },
  },
];
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.

{
  "extends": ["plugin:vitest/recommended"],
  "settings" :{
    "vitest": {
      "typecheck": true,
    }
  }
}

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-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-assertionsSuggest using expect assertions instead of callbacks🌐💡
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 06 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