{
"path": "/writing/code-formatting-guidelines",
"site": "at://did:plc:m25hu5wadnbqnt47zep7xza6/site.standard.publication/self",
"$type": "site.standard.document",
"title": "Code Formatting Guidelines",
"description": "The formatting rules I use across my projects.",
"publishedAt": "2026-04-02T00:00:00.000Z",
"textContent": "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](https://oxc.rs/docs/guide/usage/formatter.html) as the formatter.\n\n## Quick Start\n\n```ts frame=\"code\" title=\"oxfmt.config.ts\"\nimport { defineConfig } from \"oxfmt\";\n// https://t128n.dev/writing/code-formatting-guidelines\nexport default defineConfig({\n\tprintWidth: 80,\n\n\tuseTabs: true,\n\ttabWidth: 4,\n\n\tsemi: true,\n\tsingleQuote: false,\n\ttrailingComma: \"all\",\n\n\tsortImports: {},\n\tsortPackageJson: {},\n\tsortTailwindcss: {},\n\n\tignorePatterns: [\"**/*.mdc\", \"content/**/*.md\"],\n});\n```\n\n## Rules\n\n### Formatting\n\n- `printWidth` (`integer`, default `80`): Soft line length limit. Lines exceeding this will be wrapped where possible.\n- `semi` (`boolean`, default `true`): Always add semicolons. Avoids ambiguous ASI edge cases.\n- `singleQuote` (`boolean`, default `false`): Use double quotes. Consistent with JSON and most framework conventions.\n- `trailingComma` (`string`): Add trailing commas wherever valid. Keeps diffs clean on multi-line additions.\n\n### Indentation\n\n- `useTabs` (`boolean`, default `true`): Indent with tabs. Allows each developer to set their own visual width.\n- `tabWidth` (`integer`, default `4`): Visual width of a tab character. Has no effect on the emitted output.\n\n### Sorting\n\n- `sortImports` (`object`): Automatically sort import statements.\n- `sortPackageJson` (`object`): Automatically sort `package.json` keys.\n- `sortTailwindcss` (`object`): Automatically sort Tailwind CSS class names.\n\n### Ignored Paths\n\n- `ignorePatterns` (`string[]`): Paths excluded from formatting. Markdown content and MDC components are skipped to avoid interference with prose."
}