Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code-formatter

npm install @ferrow/code-formatter

CI

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

What this is

  • Detection: for prettier, eslint, and biome, checks whether the project is configured (a recognized config file, or a package.json key like "prettier") and separately whether the binary is installed (node_modules/.bin/<name> or on PATH). 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.spawnSync with the correct args: --write in write mode, --check in check mode (prettier/biome), --fix vs. plain invocation for eslint.
  • A unified report per file: { file, formatter, status } where status is changed | clean | error | not-installed | not-configured | no-formatter.

What this is NOT

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

Quickstart

npm install
npm run build
node dist/examples/demo.js

API

import { 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' }, ...]

Demo: a project with a prettier config but no installed prettier

$ 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

License

MIT


Sponsored by Ferrow


Part of the ferrow-toolkit collection · Sponsored by Ferrow

About

One command to run whichever formatters your repo already uses. Detects prettier/eslint/biome by config file + installed binary, runs them, reports a unified per-file result.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages