0.5.4 β€’ Published 15 days ago

eslint-plugin-vitest v0.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
15 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 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-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πŸŒπŸ”§
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

@crnvl96/eslint-config-node@crnvl96/eslint-config-react@jarisinc/eslint-config-jaris@everything-registry/sub-chunk-1615@ifshizuku/eslint-config-basic@ventsislavnikolov/eslint-config@zoobzio/bedrock@zoobzio/foundation-layer@daopk/eslint-config-teststitch-node@infinitebrahmanuniverse/nolb-eslint-plugin-v@innocenzi/eslint-configbisnow-eslint-config@inferrinizzard/eslint-config@ivanmaxlogiudice/eslint-config@energise/style-guide@erhang/eslint-config@jakubmazanec/eslint-configbundled-eslint-config@jakubserwin/eslint-config-vue@jdpnielsen/eslint-flat-config@eslint-config-globex/vitest@eslint-config-liebe/eslint-config-vitest@eslint-config-liebe/vitest@jsse/eslint-config@lokalise/eslint-config-frontend@luxass/eslint-config@joabesv/eslint-config@estjs/eslint-config@lshay/eslint-config@lshay/eslint-config-flat@longo-andrea/eslint-config-vue@lotusdevshack/eslint-config@fethcat/eslint-plugin@kainstar/eslint-config@ayuhito/eslint-config@coderwyd/eslint-config@danifoldi/eslint-plugin-eslint-presets@danifoldi/eslint-presets@djthoms/eslint-config@democrance/eslint-config@cloud-ru/eslint-config@douglasdemoura/eslint-config@fuf-stack/eslint-config-fuf@curev/eslint-config@datadayrepos/eslint-config@dhzh/eslint-config@gilbarbara/eslint-config@gipo355/eslint-config-base@chuhoman/eslint-config@debbl/eslint-config@kodehort/eslint-config@kodehort/eslint-config-kodehort@merlinalexhjp/eslint-config@kriszu/eslint-config@nyxb/eslint-config@mgcrea/eslint-config-node@mgcrea/eslint-config-react@layers.digital/eslint-config@lars-reimann/eslint-config@laserware/eslint-config@mistjs/eslint-config@mist3rbru/eslint-config@lenne.tech/eslint-config-vue@onefish/style-guide@dvcol/eslint-plugin-presets@imyangyong/eslint-config@instill-ai/eslint-config-cortex@nexusmods/eslint-plugin-nexusmods@knime/eslint-config@kirklin/eslint-config@khulnasoft/style-guide@flaminc/eslint-plugin@kmblabs/config@flandredaisuki/eslint-config@kkkaoru/eslint-config@nailiable/eslint-config@overmap-ai/core@pplancq/eslint-config@nodecfdi/eslint-config@schoero/configs@nivalis/eslint-config@saramorillon/eslint-plugin@flowr/eslint-config@mastondzn/eslint@flynoe/eslint-config-basic@lincy/eslint-config@rotki/eslint-config@pedroapy/eslint-config-base@pedroapy/eslint-config-web-react@penumbra-zone/eslint-config-custom@runespoorstack/eslint-config@rubiin/eslint-config@pengzhanbo/eslint-config@lint-my-life/eslint-config-astro@lint-my-life/eslint-config-comet@linters/eslint-config-vitest@lint-my-life/eslint-config-paintbrush@lint-my-life/eslint-config-unsorted@lint-my-life/eslint-config-unsorted-ts
0.5.4

15 days ago

0.5.3

23 days ago

0.5.2

25 days ago

0.5.0

29 days ago

0.5.1

29 days ago

0.4.2-beta.5

29 days ago

0.4.2-beta.3

1 month ago

0.4.2-beta.1

1 month ago

0.4.2-beta.2

1 month ago

0.4.1

1 month ago

0.4.0

1 month ago

0.3.26

2 months ago

0.3.25

2 months ago

0.3.24

2 months ago

0.3.23

2 months ago

0.3.22

3 months ago

0.3.21

3 months ago

0.3.20

5 months ago

0.3.19

5 months ago

0.3.18

5 months ago

0.3.17

5 months ago

0.3.16

5 months ago

0.3.15

5 months ago

0.3.14

5 months ago

0.3.13

5 months ago

0.3.12

5 months ago

0.3.6

7 months ago

0.3.8

7 months ago

0.3.3

7 months ago

0.3.9

6 months ago

0.3.10

6 months ago

0.3.2

7 months ago

0.3.0

8 months ago

0.3.1

8 months ago

0.2.7

10 months ago

0.2.8

10 months ago

0.2.6

11 months ago

0.2.3

12 months ago

0.2.5

12 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.5

1 year ago

0.2.0

1 year ago

0.2.2

1 year ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.51

1 year ago

0.0.52

1 year ago

0.0.53

1 year ago

0.0.54

1 year ago

0.0.55

1 year ago

0.0.56

1 year ago

0.0.57

1 year ago

0.0.50

1 year ago

0.0.48

1 year ago

0.0.49

1 year ago

0.0.25

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.11

2 years ago

0.0.23

1 year ago

0.0.13

2 years ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago