Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 3.27 KB

File metadata and controls

72 lines (48 loc) · 3.27 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Commands

# 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 analyze

Architecture

This 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.

Key files

  • src/plugin.ts — Entry point. Assembles the plugin object with all rules and exports two shared configs: recommended (old .eslintrc format) and flat/recommended (ESLint 9 flat config format). The build output is dist/src/plugin.js (configured in package.json exports).
  • src/custom-rules/<rule-name>.ts — One file per rule, each exports a single named constant created with ESLintUtils.RuleCreator.withoutDocs.
  • src/custom-rules/<rule-name>.spec.ts — Tests for each rule using @typescript-eslint/rule-tester's RuleTester. Tests are run with Jest and use ts-jest.
  • src/custom-rules/utils/ — Shared utilities:
    • get-expect-call-expression.ts — Extracts the expect(...) call from expect(x).toBe(y) or expect(x).not.toBe(y) patterns.
    • is-parent-a-test-function.ts — Checks if a function expression is directly inside a test() or it() call (including .each variants).
    • is-type-flag-set.ts — TypeScript type flag utility (checks union type flags).

How rules work

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 + '/../../'.

Adding a new rule

  1. Create src/custom-rules/<rule-name>.ts exporting the rule constant.
  2. Create src/custom-rules/<rule-name>.spec.ts with RuleTester tests.
  3. Register the rule in src/plugin.ts (in both plugin.rules and recommendedRules if it should be recommended).
  4. Create docs/rules/<rule-name>.md (auto-generated via npm run update:eslint-docs after build).
  5. Update src/plugin.spec.ts to include the new rule name in the exports check.

Documentation generation

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.

TypeScript config

  • tsconfig.json — Used for development and tests (includes spec files, app.e2e-spec.ts, file.ts).
  • tsconfig.build.json — Extends tsconfig.json but excludes spec files and test fixtures for production build output to dist/.

Test fixtures

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.