bun fmt uses the native OXC formatter embedded in Bun. It does not install an
npm package or launch a formatter subprocess. JavaScript, TypeScript, JSX and
JSON use the selected native formatters. A format requiring an unavailable
plugin fails explicitly.
bun fmt src
bun fmt --check src
bun fmt --write src
bun fmt --ignore-pattern 'fixtures/**' src
With no filesystem operands, Bun examines the working directory. --check
writes nothing and exits with code 1 when formatting differs. Without
--check, it writes formatted files. Filesystem discovery excludes generated
dependency directories and protected stores; explicit protected or
parent-traversing paths are rejected.
Native discovery reads nested .gitignore files consistently for implicit and
explicit roots. A Prettier configuration instead selects Prettier's
case-insensitive working-directory ignore files. An explicit --ignore-path
replaces the native default Gitignore search. Explicit symbolic-link operands
fail with code 2 without following or writing their targets.
Format standard input
--stdin-filepath supplies a virtual name to select the parser. Bun reads UTF-8
source from standard input and writes formatted source to standard output. It
never opens or writes the virtual file. Input is bounded to 8 MiB.
printf 'const answer=42' | bun fmt --stdin-filepath input.ts
printf 'const answer=42' | bun fmt --stdin-filepath input.ts --check
In this mode --check produces no source output and returns 1 on a difference.
--write alone still prints formatted standard input; it never writes the
virtual file. Filesystem operands and repeated virtual-name options are rejected.
Invalid UTF-8, syntax, unsupported formats and invalid options return code 2.
The virtual filename selects configuration discovery. Pass --config to choose
project formatting options explicitly.
Configuration
Filesystem formatting discovers .oxfmtrc.json or .oxfmtrc.jsonc and
.editorconfig through the native formatter. -c or --config selects an
explicit configuration.
{
"printWidth": 120,
"semi": true,
"singleQuote": false
}
bun fmt --config .oxfmtrc.json src
The native CLI accepts --check, --write, --stdin-filepath, --config and
--ignore-pattern. Other native options fail explicitly. Workspace selection,
Git-ref selection and external formatter options are not inferred from these
flags.
Use bun lint for lint diagnostics and fixes.