eslint-plugin-vitest
Eslint plugin for vitest
Last updated 7 months ago by veritem .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install eslint-plugin-vitest 
SYNC missed versions from official npm registry.

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-filename require .spec test file pattern 🌐
consistent-test-it enforce using test or it but not both 🌐 🔧
expect-expect enforce having expectation in test body
max-expects enforce a maximum number of expect per test 🌐
max-nested-describe require describe block to be less than set max value or default value 🌐
no-alias-methods disallow alias methods 🌐 🔧
no-commented-out-tests disallow commented out tests
no-conditional-expect disallow conditional expects 🌐
no-conditional-in-test disallow conditional tests 🌐
no-conditional-tests disallow conditional tests 🌐
no-disabled-tests disallow disabled tests 🌐
no-done-callback disallow using a callback in asynchronous tests and hooks 🌐 💡
no-duplicate-hooks disallow duplicate hooks and teardown hooks 🌐
no-focused-tests disallow focused tests 🌐 🔧
no-hooks disallow setup and teardown hooks 🌐
no-identical-title disallow identical titles 🔧
no-import-node-test disallow importing node:test 🔧
no-interpolation-in-snapshots disallow string interpolation in snapshots 🌐 🔧
no-large-snapshots disallow large snapshots 🌐
no-mocks-import disallow importing from mocks directory 🌐
no-restricted-matchers disallow the use of certain matchers 🌐
no-restricted-vi-methods disallow specific vi. methods 🌐
no-standalone-expect disallow using expect outside of it or test blocks 🌐
no-test-prefixes disallow using test as a prefix 🌐 🔧
no-test-return-statement disallow return statements in tests 🌐
prefer-called-with enforce using toBeCalledWith() or toHaveBeenCalledWith() 🌐 🔧
prefer-comparison-matcher enforce using the built-in comparison matchers 🌐 🔧
prefer-each enforce using each rather than manual loops 🌐
prefer-equality-matcher enforce using the built-in quality matchers 🌐 💡
prefer-expect-assertions enforce using expect assertions instead of callbacks 🌐 💡
prefer-expect-resolves enforce using expect().resolves over expect(await ...) syntax 🌐 🔧
prefer-hooks-in-order enforce having hooks in consistent order 🌐
prefer-hooks-on-top enforce having hooks before any test cases 🌐
prefer-lowercase-title enforce lowercase titles 🌐 🔧
prefer-mock-promise-shorthand enforce mock resolved/rejected shorthands for promises 🌐 🔧
prefer-snapshot-hint enforce including a hint with external snapshots 🌐
prefer-spy-on enforce using vi.spyOn 🌐 🔧
prefer-strict-equal enforce strict equal over equal 🌐 💡
prefer-to-be enforce using toBe() 🌐 🔧
prefer-to-be-falsy enforce using toBeFalsy() 🌐 🔧
prefer-to-be-object enforce using toBeObject() 🌐 🔧
prefer-to-be-truthy enforce using toBeTruthy 🌐 🔧
prefer-to-contain enforce using toContain() 🌐 🔧
prefer-to-have-length enforce using toHaveLength() 🌐 🔧
prefer-todo enforce using test.todo 🌐 🔧
require-hook require setup and teardown to be within a hook 🌐
require-local-test-context-for-concurrent-snapshots require local Test Context for concurrent snapshot tests
require-to-throw-message require toThrow() to be called with an error message 🌐
require-top-level-describe enforce that all tests are in a top-level describe 🌐
valid-describe-callback enforce valid describe callback
valid-expect enforce valid expect() usage
valid-title enforce 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

Current Tags

  • 0.5.4                                ...           latest (7 months ago)

96 Versions

  • 0.5.4                                ...           7 months ago
  • 0.5.3                                ...           7 months ago
  • 0.5.2                                ...           7 months ago
  • 0.5.1                                ...           7 months ago
  • 0.5.0                                ...           7 months ago
  • 0.4.2-beta.5                                ...           7 months ago
  • 0.4.2-beta.3                                ...           7 months ago
  • 0.4.2-beta.2                                ...           7 months ago
  • 0.4.2-beta.1                                ...           7 months ago
  • 0.4.1                                ...           7 months ago
  • 0.4.0                                ...           8 months ago
  • 0.3.26                                ...           8 months ago
  • 0.3.25                                ...           8 months ago
  • 0.3.24                                ...           8 months ago
  • 0.3.23                                ...           8 months ago
  • 0.3.22                                ...           9 months ago
  • 0.3.21                                ...           10 months ago
  • 0.3.20                                ...           a year ago
  • 0.3.19                                ...           a year ago
  • 0.3.18                                ...           a year ago
  • 0.3.17                                ...           a year ago
  • 0.3.16                                ...           a year ago
  • 0.3.15                                ...           a year ago
  • 0.3.14                                ...           a year ago
  • 0.3.13                                ...           a year ago
  • 0.3.12                                ...           a year ago
  • 0.3.10                                ...           a year ago
  • 0.3.9                                ...           a year ago
  • 0.3.8                                ...           a year ago
  • 0.3.6                                ...           a year ago
  • 0.3.3                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.8                                ...           a year ago
  • 0.2.7                                ...           a year ago
  • 0.2.6                                ...           a year ago
  • 0.2.5                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.2                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.5                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.57                                ...           2 years ago
  • 0.0.56                                ...           2 years ago
  • 0.0.55                                ...           2 years ago
  • 0.0.54                                ...           2 years ago
  • 0.0.53                                ...           2 years ago
  • 0.0.52                                ...           2 years ago
  • 0.0.51                                ...           2 years ago
  • 0.0.50                                ...           2 years ago
  • 0.0.49                                ...           2 years ago
  • 0.0.48                                ...           2 years ago
  • 0.0.47                                ...           2 years ago
  • 0.0.46                                ...           2 years ago
  • 0.0.44                                ...           2 years ago
  • 0.0.43                                ...           2 years ago
  • 0.0.42                                ...           2 years ago
  • 0.0.41                                ...           2 years ago
  • 0.0.40                                ...           2 years ago
  • 0.0.39                                ...           2 years ago
  • 0.0.38                                ...           2 years ago
  • 0.0.37                                ...           2 years ago
  • 0.0.36                                ...           2 years ago
  • 0.0.35                                ...           2 years ago
  • 0.0.34                                ...           2 years ago
  • 0.0.33                                ...           2 years ago
  • 0.0.32                                ...           2 years ago
  • 0.0.31                                ...           2 years ago
  • 0.0.30                                ...           2 years ago
  • 0.0.29                                ...           2 years ago
  • 0.0.28                                ...           2 years ago
  • 0.0.27                                ...           2 years ago
  • 0.0.25                                ...           2 years ago
  • 0.0.23                                ...           2 years ago
  • 0.0.22                                ...           2 years ago
  • 0.0.21                                ...           2 years ago
  • 0.0.20                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           2 years ago
  • 0.0.17                                ...           2 years ago
  • 0.0.16                                ...           2 years ago
  • 0.0.15                                ...           2 years ago
  • 0.0.14                                ...           2 years ago
  • 0.0.13                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.8                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE