{"id":20011,"library":"eslint-vitest-rule-tester","title":"eslint-vitest-rule-tester","description":"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.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/antfu-collective/eslint-vitest-rule-tester","tags":["javascript","eslint","vitest","rule-tester","typescript"],"install":[{"cmd":"npm install eslint-vitest-rule-tester","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-vitest-rule-tester","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-vitest-rule-tester","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for rule testing","package":"eslint","optional":false},{"reason":"peer dependency for test runner integration","package":"vitest","optional":false}],"imports":[{"note":"ESM-only package; require() will fail if not using a bundler with ESM interop.","wrong":"const { run } = require('eslint-vitest-rule-tester')","symbol":"run","correct":"import { run } from 'eslint-vitest-rule-tester'"},{"note":"createRuleTester is a named export, not default.","wrong":"import createRuleTester from 'eslint-vitest-rule-tester'","symbol":"createRuleTester","correct":"import { createRuleTester } from 'eslint-vitest-rule-tester'"},{"note":"runClassic is exported from the main entry point, no subpath.","wrong":"import { runClassic } from 'eslint-vitest-rule-tester/classic'","symbol":"runClassic","correct":"import { runClassic } from 'eslint-vitest-rule-tester'"}],"quickstart":{"code":"import { run } from 'eslint-vitest-rule-tester';\nimport { expect } from 'vitest';\n\n// Define a simple ESLint rule (example)\nconst myRule = {\n  meta: { fixable: 'code', messages: { noLet: 'Use const instead of let.' } },\n  create(context) {\n    return {\n      VariableDeclaration(node) {\n        if (node.kind === 'let') {\n          context.report({\n            node,\n            messageId: 'noLet',\n            fix(fixer) {\n              return fixer.replaceTextRange(\n                [node.range[0], node.range[0] + 3],\n                'const'\n              );\n            }\n          });\n        }\n      }\n    };\n  }\n};\n\nrun({\n  name: 'no-let',\n  rule: myRule,\n  parserOptions: { ecmaVersion: 2020, sourceType: 'module' },\n  valid: [\n    'const foo = 1'\n  ],\n  invalid: [\n    {\n      code: 'let foo = 1',\n      output(output) {\n        expect(output).toMatchInlineSnapshot('\"const foo = 1;\"');\n      },\n      errors(errors) {\n        expect(errors).toHaveLength(1);\n        expect(errors[0].messageId).toBe('noLet');\n      }\n    }\n  ]\n});","lang":"typescript","description":"Demonstrates the run() function with a custom rule, snapshotting output and errors."},"warnings":[{"fix":"Upgrade ESLint to v9.10 or higher.","message":"Requires ESLint v9.10+ (v3.0.0+)","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If you relied on @types/eslint types, install them separately.","message":"Dropped @types/eslint dependency (v2.3.0+)","severity":"breaking","affected_versions":">=2.3.0"},{"fix":"Use dynamic import() or switch to ESM in your project.","message":"ESM-only package; CommonJS require() may fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to v3.0.0+ for Vitest v4 support.","message":"Vitest v4 is allowed since v3.0.0","severity":"deprecated","affected_versions":"<3.0.0"},{"fix":"Upgrade to v2.0.0+ to use async output/errors/after/before.","message":"Async hooks are not supported before v2.0.0","severity":"gotcha","affected_versions":"<2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install -D eslint-vitest-rule-tester'.","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'eslint-vitest-rule-tester'"},{"fix":"Use 'import { run } from 'eslint-vitest-rule-tester''.","cause":"Using wrong import syntax (named vs default) or typo.","error":"export 'run' (imported as 'run') was not found in 'eslint-vitest-rule-tester'"},{"fix":"Use 'run()' or 'createRuleTester()' instead.","cause":"Trying to instantiate RuleTester from this package; it exports functions, not classes.","error":"RuleTester is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}