npm install @ferrow/code-formatterOne command to run whichever formatters your repo already uses. This is a formatter runner, not a formatter — it doesn't reimplement prettier or eslint's rules, it detects your project's config, finds the installed binary, and runs it correctly.
- Detection: for
prettier,eslint, andbiome, checks whether the project is configured (a recognized config file, or apackage.jsonkey like"prettier") and separately whether the binary is installed (node_modules/.bin/<name>or onPATH). These are reported as two independent booleans — "configured but not installed" is a normal, first-class result, not an error swallowed into silence. - Extension-to-formatter mapping (
.js/.ts→ prettier/eslint,.json→ prettier/biome, etc.), preferring a formatter that's both configured and installed. - Runs the resolved binary via
child_process.spawnSyncwith the correct args:--writein write mode,--checkin check mode (prettier/biome),--fixvs. plain invocation for eslint. - A unified report per file:
{ file, formatter, status }where status ischanged | clean | error | not-installed | not-configured | no-formatter.
- Not a formatter implementation — no rule engine, no AST, no style decisions of its own.
- Not a linter — it shells out to eslint, it doesn't implement lint rules.
- Not a config generator — it reads existing config, it doesn't write one.
npm install
npm run build
node dist/examples/demo.jsimport { detectFormatters, runFormatters, FORMATTERS } from 'code-formatter';
const statuses = detectFormatters(projectDir, FORMATTERS);
// [{ name: 'prettier', configured: true, installed: false, def: {...} }, ...]
const reports = runFormatters(projectDir, ['src/a.js', 'README.md'], { mode: 'check' });
// [{ file: 'src/a.js', formatter: 'prettier', status: 'changed' }, ...]$ node dist/examples/demo.js
--- detection ---
prettier: configured=true installed=false
eslint: configured=false installed=false
biome: configured=false installed=false
--- run (check mode) ---
sample.js: formatter=prettier status=not-installed (prettier is configured but its binary was not found in node_modules/.bin or PATH)
readme.txt: formatter=none status=no-formatter
MIT
Sponsored by Ferrow
Part of the ferrow-toolkit collection · Sponsored by Ferrow