This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build (compile TypeScript to dist/)
npm run build
# Run all tests
npm test
# Run a single test file
npx jest src/custom-rules/no-useless-matcher-to-be-defined.spec.ts --runInBand
# Lint
npm run lint
npm run lint:fix
# Format check / fix
npm run format
npm run format:fix
# Lint markdown docs
npm run lint:docs
# Regenerate rule docs in README.md and docs/rules/ (requires build first)
npm run update:eslint-docs
# Run full CI check (format + lint + lint:docs + lint:eslint-docs + test)
npm run analyzeThis is an ESLint plugin that provides custom lint rules for test files. It uses @typescript-eslint/utils to write typed AST rules that leverage TypeScript type information.
src/plugin.ts— Entry point. Assembles the plugin object with all rules and exports two shared configs:recommended(old.eslintrcformat) andflat/recommended(ESLint 9 flat config format). The build output isdist/src/plugin.js(configured inpackage.jsonexports).src/custom-rules/<rule-name>.ts— One file per rule, each exports a single named constant created withESLintUtils.RuleCreator.withoutDocs.src/custom-rules/<rule-name>.spec.ts— Tests for each rule using@typescript-eslint/rule-tester'sRuleTester. Tests are run with Jest and usets-jest.src/custom-rules/utils/— Shared utilities:get-expect-call-expression.ts— Extracts theexpect(...)call fromexpect(x).toBe(y)orexpect(x).not.toBe(y)patterns.is-parent-a-test-function.ts— Checks if a function expression is directly inside atest()orit()call (including.eachvariants).is-type-flag-set.ts— TypeScript type flag utility (checks union type flags).
Rules use ESLintUtils.getParserServices(context) to access the TypeScript type checker, enabling type-aware linting (e.g., detecting if a variable can be undefined). Test spec files configure RuleTester with parserOptions.project pointing to tsconfig.json at __dirname + '/../../'.
- Create
src/custom-rules/<rule-name>.tsexporting the rule constant. - Create
src/custom-rules/<rule-name>.spec.tswithRuleTestertests. - Register the rule in
src/plugin.ts(in bothplugin.rulesandrecommendedRulesif it should be recommended). - Create
docs/rules/<rule-name>.md(auto-generated vianpm run update:eslint-docsafter build). - Update
src/plugin.spec.tsto include the new rule name in the exports check.
Rule docs (docs/rules/*.md) and the rules table in README.md are auto-generated by eslint-doc-generator. Run npm run update:eslint-docs to regenerate. Config is in .eslint-doc-generatorrc.js.
tsconfig.json— Used for development and tests (includes spec files,app.e2e-spec.ts,file.ts).tsconfig.build.json— Extendstsconfig.jsonbut excludes spec files and test fixtures for production build output todist/.
app.e2e-spec.ts and file.ts at the root are fixture files used by rule tests (as filename in RuleTester test cases) to satisfy TypeScript project requirements.