Consistent formatting removes noise from code review and keeps a codebase readable as it grows. These are the rules I’ve settled on across my projects, using oxfmt as the formatter.
Quick Start
import { defineConfig } from "oxfmt";// https://t128n.dev/writing/code-formatting-guidelinesexport default defineConfig({ printWidth: 80,
useTabs: true, tabWidth: 4,
semi: true, singleQuote: false, trailingComma: "all",
sortImports: {}, sortPackageJson: {}, sortTailwindcss: {},
ignorePatterns: ["**/*.mdc", "content/**/*.md"],});Rules
Formatting
printWidth(integer, default80): Soft line length limit. Lines exceeding this will be wrapped where possible.semi(boolean, defaulttrue): Always add semicolons. Avoids ambiguous ASI edge cases.singleQuote(boolean, defaultfalse): Use double quotes. Consistent with JSON and most framework conventions.trailingComma(string): Add trailing commas wherever valid. Keeps diffs clean on multi-line additions.
Indentation
useTabs(boolean, defaulttrue): Indent with tabs. Allows each developer to set their own visual width.tabWidth(integer, default4): Visual width of a tab character. Has no effect on the emitted output.
Sorting
sortImports(object): Automatically sort import statements.sortPackageJson(object): Automatically sortpackage.jsonkeys.sortTailwindcss(object): Automatically sort Tailwind CSS class names.
Ignored Paths
ignorePatterns(string[]): Paths excluded from formatting. Markdown content and MDC components are skipped to avoid interference with prose.