$ show vitest-dev/eslint-plugin-vitest
This repository is an ESLint plugin for the Vitest testing framework, providing over 60 lint rules to enforce best practices, catch common errors, and maintain code style in test files. It is a library consumed by ESLint, not a standalone application. The plugin exports a flat config (recommended, all) and an environment configuration for Vitest globals. The codebase is well-structured with a consistent rule creation pattern using a factory utility (`createEslintRule`), centralized Vitest function call parsing (`parseVitestFnCall`), and a reusable padding rule factory (`createPaddingRule`). It relies on `@typescript-eslint/utils` for AST analysis and is designed for ESLint v9+ with flat config. The project is actively maintained with CI/CD, automated releases, and comprehensive test coverage for each rule.
The LLM identified 4 files worth highlighting for reuse:
Provides a `createPaddingRule` factory that generates ESLint rules enforcing blank lines around specific blocks (e.g., after-each, before-each). It abstracts common logic for padding rules, reducing duplication across 8+ similar rules. The factory is self-contained, parameterized by block type and location, and could be extracted to create padding rules for any ESLint plugin.
Central utility for identifying Vitest-specific function calls (`test`, `describe`, `expect`, `vi`, etc.) in AST nodes. Uses a `WeakMap` cache for performance and returns structured information about the call type, modifiers, and matchers. This is a non-trivial pattern that could be reused in other tools analyzing Vitest code (e.g., custom formatters, code mods).
Exports a `Set` of all valid chained method calls for Vitest functions (e.g., `test.skip.only.each`, `describe.only.concurrent`). This set is generated by a script (`scripts/chain-permutations.ts`) and used by multiple rules to validate call chains. The pattern of generating exhaustive valid combinations is reusable for any API with complex chaining.
Provides helper functions for ESLint fixers, such as `removeVariableDeclarator` and `removeNodeFromArray`. These are generic AST manipulation utilities that can be reused across any ESLint plugin requiring automated fixes, not just Vitest-specific rules.