Configuration
Advanced oxfmt configuration options
Override formatting defaults
Spread the shared config first, then override the options your project needs to change.
import sharedConfig from "@octopus-energy/oxc/oxfmt/config";
import { defineConfig } from "oxfmt";
export default defineConfig({
...sharedConfig,
printWidth: 120,
});See the API reference for the exported defaults.
Ignore patterns
Use
ignorePatterns
for generated output, build directories, framework caches, and lockfiles.
import sharedConfig from "@octopus-energy/oxc/oxfmt/config";
import { defineConfig } from "oxfmt";
export default defineConfig({
...sharedConfig,
ignorePatterns: [
"public/**",
"**/node_modules/**",
"**/dist/**",
"**/.next/**",
"pnpm-lock.yaml",
],
});Import sorting
The shared config enables
sortImports
with groups for side effects, Node built-ins, external imports, internal
aliases, and relative imports.
Import groups are separated by blank lines by default. Set newlinesBetween to
false to keep sorted imports together.
import sharedConfig from "@octopus-energy/oxc/oxfmt/config";
import { defineConfig } from "oxfmt";
export default defineConfig({
...sharedConfig,
sortImports: {
...sharedConfig.sortImports,
newlinesBetween: false,
},
});JSON config
It is not possible to directly extend from a JSON file within an .oxfmtrc.json
file. The shared configuration is simple enough to copy if the additional
TypeScript config startup cost matters:
Speed up oxfmt with JSON config
TypeScript configuration files need a Node.js instance to load, which adds a small startup cost. Use JSON configs if that overhead matters for your project.