MCP TypeScript SDK (V2) / @modelcontextprotocol/codemod / utils/detectFormatter
utils/detectFormatter
Interfaces
DetectedFormatter
Defined in: utils/detectFormatter.ts:6
A code formatter the codemod can recommend running after a migration.
Properties
bin
bin:
string
Defined in: utils/detectFormatter.ts:10
Executable name, e.g. prettier.
name
name:
string
Defined in: utils/detectFormatter.ts:8
Display name, e.g. Prettier.
writeArgs
writeArgs: readonly
string[]
Defined in: utils/detectFormatter.ts:12
Arguments that write formatting in place; changed file paths are appended after these.
Functions
detectFormatter()
detectFormatter(
startDir,homeDir?):DetectedFormatter|null
Defined in: utils/detectFormatter.ts:99
Walks up from startDir looking for a configured code formatter, so the CLI can suggest the right "format your changed files" command after a migration.
The walk is bounded so a user-level global config is never mistaken for the project's. It stops at the repository root (a .git directory) or the filesystem root, and — for a project that is not a git checkout (tarball, fresh scaffold, CI workspace) — never ascends into or above $HOME, so a ~/.prettierrc, ~/biome.json, or ~/package.json with formatter deps is never matched. (A .git boundary alone did not hold this guarantee for non-git projects, which would otherwise walk to $HOME.)
Detection is config-based and runs nothing. When multiple formatters are configured, precedence is Biome > Prettier > ESLint.
Parameters
startDir
string
the directory to start the upward search from.
homeDir?
string = ...
the user's home directory; the walk never reads it or any ancestor. Injectable for tests; defaults to os.homedir().
Returns
DetectedFormatter | null
the detected formatter, or null if none is configured.