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.3.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
244K
decreased by-53.27%
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-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-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 03 Nov 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