Skip to content

Configuration

Oxfmt works out of the box, but most teams commit a configuration file to keep formatting consistent across local runs, editors, and CI.

This page focuses on project configuration: formatting options, ignore patterns, and experimental features.

Create a config file

To generate a starter config in the current directory:

sh
oxfmt --init

Oxfmt automatically looks for .oxfmtrc.json or .oxfmtrc.jsonc starting from the current directory and walking up the tree. You can also pass a config explicitly:

sh
oxfmt -c path/to/yourconfig.json

A minimal configuration looks like this:

.oxfmtrc.json
json
{
  "$schema": "./node_modules/oxfmt/configuration_schema.json",
  "printWidth": 80
}

Configuration file format

A configuration file is a JSON object. The most common top-level fields are:

  • printWidth: Line width limit (default: 100)
  • tabWidth: Spaces per indentation level (default: 2)
  • useTabs: Use tabs instead of spaces (default: false)
  • semi: Add semicolons (default: true)
  • singleQuote: Use single quotes (default: false)
  • trailingComma: Trailing commas in multi-line structures (default: "all")
  • ignorePatterns: Glob patterns to exclude from formatting
  • experimentalSortImports: Configure import sorting (disabled by default)
  • experimentalSortPackageJson: Configure package.json sorting (enabled by default)
  • experimentalTailwindcss: Configure Tailwind class sorting (disabled by default)

For a complete list of fields, see the Config file reference.

JSON schema

Add a $schema field for editor validation and autocomplete:

.oxfmtrc.json
json
{
  "$schema": "./node_modules/oxfmt/configuration_schema.json"
}

.editorconfig

Oxfmt reads these .editorconfig properties:

  • end_of_lineendOfLine
  • indent_styleuseTabs
  • indent_sizetabWidth
  • max_line_lengthprintWidth
  • insert_final_newlineinsertFinalNewline

Both root section and glob-based overrides are supported.

[*]
indent_size = 4

[*.{js,ts}]
indent_size = 2

Oxfmt uses only the nearest .editorconfig from the current directory:

  • root = true is not respected
  • Nested .editorconfig files are not merged

Precedence

Options are applied in order (lowest to highest priority):

  1. Defaults
  2. .oxfmtrc.json(c) root options
  3. .oxfmtrc.json(c) overrides options
  4. fallback to options supported by .editorconfig for unset fields

Oxfmt-specific options

insertFinalNewline

Controls whether a final newline is added to formatted files. Defaults to true.

This is a frequently requested Prettier feature, as some environments (e.g., Salesforce) strip trailing newlines.

printWidth

Oxfmt defaults to printWidth: 100 (Prettier uses 80). Reasons:

  • TypeScript code is longer due to type annotations
  • Import statements often have many specifiers
  • Modern screens are wider
  • Fewer line breaks mean fewer LLM tokens

To match Prettier's default:

.oxfmtrc.json
json
{
  "printWidth": 80
}

Next steps