Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
eslint-plugin-vitest
Advanced tools
Eslint plugin for vitest
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-vitest
:
npm install eslint-plugin-vitest --save-dev
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
}
]
}
}
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,
},
},
},
]
πΌ 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 | β | π§ |
FAQs
Eslint plugin for vitest
The npm package eslint-plugin-vitest receives a total of 450,404 weekly downloads. As such, eslint-plugin-vitest popularity was classified as popular.
We found that eslint-plugin-vitest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.