oxfmt CLI Reference
oxfmt is a high-performance code formatter for JavaScript, TypeScript, JSX, TSX, and more. It’s designed to be compatible with Prettier while offering improved performance and additional features.Installation
Basic Usage
Commands
Default Command (Format)
The default command formats files and writes them in place.Special Commands
Initialize
.oxfmtrc.json configuration file with default values.Migrate configuration from another formatter to
.oxfmtrc.json.Available sources:prettier- Migrate from Prettier configurationbiome- Migrate from Biome configuration
Start Language Server Protocol (LSP) server for editor integration.
Specify file name for stdin input to infer which parser to use.
Output Mode Options
Format and write files in place (default behavior).This is the default mode when no output option is specified.
Check if files are formatted without writing changes.Displays statistics and exits with error code if files need formatting.
Useful for CI/CD pipelines.
List files that would be changed by formatting.Does not write changes or show statistics. Outputs only file paths.
Configuration Options
Path to the configuration file.If not specified, oxfmt searches for
.oxfmtrc.json in the current directory and parent directories.Ignore Options
Path to ignore file(s). Can be specified multiple times.If not specified,
.gitignore and .prettierignore in the current directory are used automatically.Format code in
node_modules directory.By default, node_modules is skipped.Runtime Options
Do not exit with error when pattern is unmatched.By default, oxfmt exits with error code 2 if no files match the provided patterns.
Number of threads to use for formatting.Set to 1 to use only 1 CPU core. By default, uses all available CPU cores.
Path Arguments
Paths can be files, directories, or glob patterns... (parent directory references).
Exit Codes
oxfmt uses the following exit codes:| Exit Code | Meaning |
|---|---|
| 0 | Success - all files properly formatted |
| 1 | Format mismatch - files need formatting (in --check or --list-different mode), or invalid configuration |
| 2 | Fatal error - no files found or formatting failed |
-
0 (Success)
- All files are properly formatted (or were formatted successfully)
- No files matched with
--no-error-on-unmatched-patternflag - Special commands (
--init,--migrate,--lsp) succeeded
-
1 (Warning/Mismatch)
- Configuration file is invalid
- Files need formatting (when using
--checkor--list-different)
-
2 (Fatal Error)
- No files found matching the given patterns
- Formatting failed due to syntax errors or other issues
Configuration File
oxfmt uses.oxfmtrc.json for configuration. The format is compatible with Prettier’s options.
Example .oxfmtrc.json
Configuration Options
Core Formatting Options
Specify the line length that the formatter will wrap on.Corresponds to Prettier’s
printWidth. Overrides .editorconfig.max_line_length.Specify the number of spaces per indentation level.Overrides
.editorconfig.indent_size.Indent lines with tabs instead of spaces.Overrides
.editorconfig.indent_style.Which end of line characters to apply.Options:
"lf"- Line Feed only (\n), common on Linux and macOS"crlf"- Carriage Return + Line Feed (\r\n), common on Windows"cr"- Carriage Return only (\r)
"auto" is not supported.Overrides .editorconfig.end_of_line.Quote and Punctuation Options
Use single quotes instead of double quotes.For JSX, use
jsxSingleQuote instead.Use single quotes instead of double quotes in JSX.
Change when properties in objects are quoted.Options:
"as-needed"- Only add quotes around object properties when required"consistent"- If at least one property requires quotes, quote all properties"preserve"- Respect the input formatting
Print trailing commas wherever possible in multi-line comma-separated structures.Options:
"all"- Trailing commas wherever possible"es5"- Trailing commas where valid in ES5 (objects, arrays)"none"- No trailing commas
Print semicolons at the ends of statements.
true- Add semicolons (default)false- Only add semicolons at the beginning of lines that may introduce ASI failures
Spacing and Layout Options
Print spaces between brackets in object literals.
true-{ foo: bar }(default)false-{foo: bar}
Put the
> of a multi-line HTML element at the end of the last line instead of on the next line.Applies to HTML, JSX, Vue, and Angular. Does not apply to self-closing elements.Include parentheses around a sole arrow function parameter.Options:
"always"- Always include parentheses (default)"avoid"- Omit parentheses when possible
Enforce single attribute per line in HTML, Vue, and JSX.
Advanced Options
How to wrap object literals when they could fit on one line or span multiple lines.Options:
"preserve"- Format as multi-line if there’s a newline before the first property (default)"always"- Always format objects as multi-line"never"- Always format objects on one line if possible
Control whether to format embedded code (CSS-in-JS, JS-in-Vue, etc.).Options:
"auto"- Format embedded code if the formatter can (default)"off"- Never format embedded code
Markdown Options
How to wrap prose in Markdown.Options:
"preserve"- Wrap prose as-is (default)"always"- Wrap prose to print width"never"- Never wrap prose (use soft wrapping)
HTML/Vue Options
Specify global whitespace sensitivity for HTML, Vue, Angular, and Handlebars.Options:
"css"- Respect CSS display property (default)"strict"- All whitespace is significant"ignore"- All whitespace is insignificant
Whether to indent code inside
<script> and <style> tags in Vue files.Oxfmt Extensions
Whether to insert a final newline at the end of the file.Overrides
.editorconfig.insert_final_newline.File Overrides
You can specify different formatting options for specific files using theoverrides array.
Ignore Patterns
You can specify files to ignore in the configuration file:EditorConfig Support
oxfmt respects.editorconfig files when present. Configuration file options take precedence over EditorConfig.
Supported EditorConfig properties:
indent_style(overridden byuseTabs)indent_size(overridden bytabWidth)end_of_line(overridden byendOfLine)max_line_length(overridden byprintWidth)insert_final_newline(overridden byinsertFinalNewline)
Integration Examples
CI/CD Integration
GitHub Actions
GitLab CI
Pre-commit Hook
Using Husky
Using lint-staged
NPM Scripts
VS Code Integration
Create.vscode/settings.json:
Supported File Types
oxfmt can format the following file types:- JavaScript (
.js,.mjs,.cjs) - TypeScript (
.ts,.mts,.cts) - JSX (
.jsx) - TSX (
.tsx) - JSON (
.json) - JSONC (
.jsonc) - JSON with comments - Vue (
.vue) - Markdown (
.md) - HTML (
.html) - CSS (
.css) - TOML (
.toml)
Performance Tips
- Use Multiple Threads: oxfmt automatically uses all available CPU cores for optimal performance.
-
Target Specific Directories: Format only the directories you need:
-
Use Ignore Files: Properly configure
.prettierignoreor.gitignoreto skip unnecessary files: -
Check Before Format: Use
--checkin CI to avoid unnecessary writes: -
Format Changed Files Only: In CI, format only changed files:
Common Use Cases
Format Everything
Check Formatting in CI
Format Specific File Types
Format with Custom Config
List Unformatted Files
Format Stdin
Migrate from Prettier
Differences from Prettier
While oxfmt aims to be compatible with Prettier, there are some differences:- Default Print Width: oxfmt defaults to
100instead of Prettier’s80 - Default Trailing Commas: oxfmt defaults to
"all"instead of Prettier’s"es5" - Performance: oxfmt is significantly faster, especially on large codebases
- Additional Options: oxfmt includes extensions like
insertFinalNewlineandobjectWrap - EditorConfig: oxfmt has deeper EditorConfig integration
Troubleshooting
No Files Found
If oxfmt reports no files found:- Check ignore patterns in
.prettierignoreor.gitignore - Verify paths are correct
- Use
--with-node-modulesif you need to format dependencies - Add
--no-error-on-unmatched-patternto suppress the error
Configuration Not Loading
- Ensure
.oxfmtrc.jsonis in the correct location - Check JSON syntax is valid (use a JSON validator)
- Use
--configto specify path explicitly - Check for conflicting
.editorconfigsettings
Formatting Errors
If oxfmt fails to format files:- Check for syntax errors in source files
- Verify file extension is supported
- Check for invalid configuration options
- Try formatting individual files to isolate the issue
Performance Issues
- Use
--threads 1to test single-threaded performance - Check ignore patterns are optimized
- Ensure you’re not formatting unnecessary files (e.g.,
node_modules)