Registry / testing / eslint-vitest-rule-tester

eslint-vitest-rule-tester

JSON →
library3.1.0jsnpmunverified

ESLint rule tester integration with Vitest, providing a modern testing experience for ESLint rules. Current stable version is 3.1.0, supporting ESLint v9.10+ and Vitest v1-v4. Key differentiators: built-in snapshot support for outputs and errors, async hooks, onResult callback for custom assertions, and TypeScript types included. Released actively by the antfu-collective, used by ESLint Stylistic and other popular plugins. No need for Vitest globals.

npm install eslint-vitest-rule-tester
INSTALL
IMPORT
SIG · ESLINT-VITEST-RULE
E
eslint-vitest-rule-tester
testingjavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

run
import { run } from 'eslint-vitest-rule-tester'
const { run } = require('eslint-vitest-rule-tester')
ESM-only package; require() will fail if not using a bundler with ESM interop.
createRuleTester
import { createRuleTester } from 'eslint-vitest-rule-tester'
import createRuleTester from 'eslint-vitest-rule-tester'
createRuleTester is a named export, not default.
runClassic
import { runClassic } from 'eslint-vitest-rule-tester'
import { runClassic } from 'eslint-vitest-rule-tester/classic'
runClassic is exported from the main entry point, no subpath.

Demonstrates the run() function with a custom rule, snapshotting output and errors.

import { run } from 'eslint-vitest-rule-tester'; import { expect } from 'vitest'; // Define a simple ESLint rule (example) const myRule = { meta: { fixable: 'code', messages: { noLet: 'Use const instead of let.' } }, create(context) { return { VariableDeclaration(node) { if (node.kind === 'let') { context.report({ node, messageId: 'noLet', fix(fixer) { return fixer.replaceTextRange( [node.range[0], node.range[0] + 3], 'const' ); } }); } } }; } }; run({ name: 'no-let', rule: myRule, parserOptions: { ecmaVersion: 2020, sourceType: 'module' }, valid: [ 'const foo = 1' ], invalid: [ { code: 'let foo = 1', output(output) { expect(output).toMatchInlineSnapshot('"const foo = 1;"'); }, errors(errors) { expect(errors).toHaveLength(1); expect(errors[0].messageId).toBe('noLet'); } } ] });
Debug
Known issues
breakingRequires ESLint v9.10+ (v3.0.0+)
fix
Upgrade ESLint to v9.10 or higher.
affects: >=3.0.0
breakingDropped @types/eslint dependency (v2.3.0+)
fix
If you relied on @types/eslint types, install them separately.
affects: >=2.3.0
gotchaESM-only package; CommonJS require() may fail.
fix
Use dynamic import() or switch to ESM in your project.
affects: >=1.0.0
deprecatedVitest v4 is allowed since v3.0.0
fix
Upgrade to v3.0.0+ for Vitest v4 support.
affects: <3.0.0
gotchaAsync hooks are not supported before v2.0.0
fix
Upgrade to v2.0.0+ to use async output/errors/after/before.
affects: <2.0.0
Errors
Common errors & fixes
Cannot find module 'eslint-vitest-rule-tester'
Package not installed or not in node_modules.
fix
Run 'npm install -D eslint-vitest-rule-tester'.
export 'run' (imported as 'run') was not found in 'eslint-vitest-rule-tester'
Using wrong import syntax (named vs default) or typo.
fix
Use 'import { run } from 'eslint-vitest-rule-tester''.
RuleTester is not a constructor
Trying to instantiate RuleTester from this package; it exports functions, not classes.
fix
Use 'run()' or 'createRuleTester()' instead.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
eslintrequiredpeer dependency for rule testing
vitestrequiredpeer dependency for test runner integration
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-vitest-rule-tester — npm install eslint-vitest-rule-tester · libregistry