1.1.8 β€’ Published 6 days ago

@vitest/eslint-plugin v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

eslint-plugin-vitest

npm ci

Eslint plugin for vitest

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install @vitest/eslint-plugin

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

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

If you're using old Eslint configuration, make sure to use legacy key like the following

{
  "extends": ["plugin:@vitest/legacy-recommended"] // or legacy-all
}

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 "@vitest/eslint-plugin";

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πŸŒπŸ”§
prefer-vi-mockedPrefer vi.mocked() over fn as MockπŸŒπŸ”§
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 and contributors

typescript-eslint-standard@arabasta/eslint-config@antfu/eslint-config@akrc/eslint-config@cany748/eslint-config@cclr/eslint-config-common@chance/eslint@2bad/axiom@2030/eslint-config@adbayb/stack@aarongoldenthal/eslint-config-standard@coderwyd/eslint-config@bernankez/eslint-config@dhzh/eslint-config@flowr/eslint-config@elora-cloud/eslint-config@estjs/eslint-config@gilbarbara/eslint-config@ktam/lint-node@kouts/eslint-config@kriszu/eslint-config@lemonbot.fun/eslint-config@lehoczky/eslint-config-vitest@iqrf/eslint-config@ithinkdt/lint@lincy/eslint-config@luxass/eslint-config@mgcrea/eslint-config-node@mgcrea/eslint-config-react@mutoe/eslint-config@neosjs/eslint-config@nerdfish/config@nhcarrigan/eslint-config@nirtamir2/eslint-config@nodecfdi/eslint-config@epic-web/config@exer7um/eslint-config@faergeek/eslint-config@mcous/eslint-config@keksiqc/eslint-config@jiangweiye/eslint-config@ivanmaxlogiudice/eslint-config@jaypie/eslint@kodehort/eslint-config@kirklin/eslint-config@jsse/eslint-config@imyangyong/eslint-config@jhqn/eslint-config@hyperse/eslint-config-hyperse@pplancq/eslint-config@re-taro/eslint-config@rainbowatcher/eslint-config-js@open-xchange/linter-presets@ntnyq/eslint-config@nyxb/eslint-config@oat-sa/eslint-config-tao@pandell/eslint-config@ourongxing/eslint-config@pengzhanbo/eslint-config@slhs/eslint-config@slashnephy/eslint-config@sparticuz/eslint-config@tabula/eslint-config@removify/eslint-config@stacksjs/eslint-config@zhangwj0520/eslint-configaberlaas-lint@dorabag/eslint-config@dethdkn/eslint-config@rotki/eslint-config@tools-aoeur/eslint-config@wakamsha/eslint-config@wangyjhh/eslint-config@vinicunca/eslint-config@unshared/eslint-config@wkovacs64/eslint-config@wiz-develop/eslint-config@wisemen/eslint-config-vue@wesp-up/eslint-config@xwbx/eslint-config@xiaohe01/eslint-configbundled-eslint-configeslint-config-archisquadeslint-config-bloqeslint-config-mister-hopeeslint-config-molindoeslint-config-prosteeslint-config-sheriffeslint-config-shinyeslint-config-tidaleslint-config-thewlabseslint-config-reeartheslint-config-chance
1.1.8

6 days ago

1.1.7

1 month ago

1.1.6

1 month ago

1.1.5

1 month ago

1.1.1

2 months ago

1.1.0

3 months ago

1.1.4

2 months ago

1.0.5

3 months ago

1.1.3

2 months ago

1.0.4

3 months ago

1.1.2

2 months ago

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago

0.0.0-0

3 months ago