How antfu/eslint-config works
Project type and purpose
• This is an open-source Node.js/TypeScript tool and library published as @antfu/eslint-config.
• It provides a factory-based API to generate ESLint Flat Configs, plus a CLI to scaffold or migrate configs in user projects.
• It ships opinionated defaults, per-language and per-framework presets, optional plugins/formatters, and a plugin-renaming mechanism.
High-level components
a. CLI layer
• bin/index.js ↔ src/cli/run.ts → orchestrates the “starter wizard” and migration commands
• Reads user input/options, invokes factory, writes eslint.config.mjs
b. Core library/API
• src/index.ts & src/factory.ts
– Exposes antfu() factory function returning a FlatConfigComposer
– Chains presets, overrides, plugin renames, etc.
c. Preset modules
• src/configs/*.ts
– Each file exports one ESLint Flat Config fragment (javascript, typescript, vue, astro, style, markdown, etc.)
d. Utilities & helpers
• src/utils.ts, src/globs.ts, src/plugins.ts, src/types.ts
• Vendored types in src/vender/prettier-types.ts
e. Scripts & build
• scripts/typegen.ts, scripts/versiongen.ts → generate type definitions and version metadata
• tsconfig.json, vitest.config.ts, eslint.config.ts, pnpm-workspace.yaml
f. CI/CD & release
• .github/workflows/ci.yml → lint, test, build
• .github/workflows/release.yml → npm publish, changelog
g. Tests & fixtures
• test/*.ts → unit tests for CLI, fixtures, types
• fixtures/input & fixtures/output → sample files and expected transformed outputs
Relationships & data flow
• User calls npx @antfu/eslint-config (CLI)
• CLI parses flags → invokes factory with options → loads needed preset modules
• Factory composes flat config(s) → applies plugin renaming, overrides → returns JSON/MJS AST
• CLI writes the config file or prints to stdout
• Tests exercise the CLI and core: read fixtures/input, run transform, compare to fixtures/output
Architectural patterns & principles
• Factory Method: antfu() constructs and composes configs
• Plugin/Module Pattern: Each language/framework support is a self-contained module under src/configs
• Composable Flat Config: uses ESLint’s new flat config API to merge multiple config fragments
• Extensibility: users can override, prepend, rename, or replace any preset via the composer API
• Automated code generation for types & versions (scripts folder)
Diagramming details
• Title: “@antfu/eslint-config Architecture”
• Layered view:
• Top: User & CLI
• Middle: Factory → Presets → Utilities
• Bottom: Output (config file), External: ESLint, npm
• Side: Tests & CI/CD