npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-vitest

v0.5.4

Published

Eslint plugin for vitest

Downloads

2,328,280

Readme

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