Skip to content

style: let Oxfmt own import order - #2186

Merged
koistya merged 1 commit into
mainfrom
style/oxfmt-sort-imports
Sep 12, 2026
Merged

koistya merged 1 commit into
mainfrom
style/oxfmt-sort-imports

Conversation

@koistya

@koistya koistya commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Import order was owned by "source.organizeImports": "explicit" in .vscode/settings.json – applied per developer, only to files someone happened to open in VS Code, never checked in CI. The drift was real rather than stylistic: apps/api/lib/app.ts was sorted because someone edited it, while packages/ui/components/button.tsx had react out of order because it is shadcn CLI output nobody touched. Oxfmt already formats every file it owns in bun run format, checks them in CI, and checks the staged ones on commit, so moving import order there adds no dependency and no extra pass.

Changes

File Change
.oxfmtrc.json "sortImports": true – defaults, nothing else
.vscode/settings.json drop source.organizeImports; editor.defaultFormatter is already oxc.oxc-vscode, so format-on-save still sorts
AGENTS.md Oxfmt owns import order – do not reintroduce an editor action or a lint rule
docs/adr/007-oxfmt-sorts-imports.md
docs/adr/005-oxlint-oxfmt.md
new ADR, plus a backlink from ADR-005 – which claims the Oxc switch "produced no formatting diff", a contract this amends, so the rationale needs a durable home
74 source files bun run format output, nothing hand-edited

Two defaults are load-bearing and deliberately not overridden:

  • sortSideEffects off – db/scripts/seed.ts keeps import "../drizzle.config" last, loading env vars before anything reads DATABASE_URL. Checked by hand in all four files where a side-effect import's position matters.
  • internalPattern untouched (["~/", "@/", "#"]) – keeps @repo/* with the externals and #* in its own group, the distinction ADR-006 draws between another package and this package's own file.

Trade-off

source.organizeImports also deleted unused imports on save; Oxfmt does not. no-unused-vars still fails CI on one, so nothing slips through – it surfaces at commit or CI time instead of silently on save, with the removal visible in the diff.

Updating a fork

Sync with the /merge-seed skill as usual. Two things are specific to this change:

  • Do not resolve the reflow by hand. Resolve conflicted hunks on content, then run bun run format and let Oxfmt settle import order for both sides. Taking either side wholesale to clear import-order noise drops imports the other side added.
  • ADR numbering may collide. Local numbering is authoritative, so renumber the incoming ADR-007 and fix its links if the fork already has an 007.

Verification

bun run format:check · bun lint · bun typecheck · bun run test -- --run (93 passed) · bun run build (4 workspaces) – all clean on the final tree.

Risk

A tree-wide reflow conflicts with anything in flight; rebase open branches right after this lands.

Follow-up to #2184 (TypeScript 7 + Oxc), split out because at 74 files it would have buried that PR's substance.

@koistya
koistya force-pushed the style/oxfmt-sort-imports branch from d24a7d3 to 4e91c44 Compare September 12, 2026 13:00
Import order was owned by `source.organizeImports` in `.vscode/settings.json`:
applied per developer, only to files someone opened in VS Code, and never
checked in CI. `sortImports` in `.oxfmtrc.json` hands it to a tool that already
runs over every file in `bun run format`, in CI and in the pre-commit hook.

Defaults only. Side-effect imports keep their position, so `db/scripts/seed.ts`
still loads `../drizzle.config` last, and `#*` subpath imports stay in their own
group instead of merging with `@repo/*` packages. ADR-007 records why.

The editor action also deleted unused imports on save, which Oxfmt does not do.
`no-unused-vars` still fails CI on one, so it surfaces at commit or CI time
instead, with the removal visible in the diff.

Everything outside the five config/doc files is `bun run format` output.
@koistya
koistya force-pushed the style/oxfmt-sort-imports branch from 4e91c44 to 4052cc3 Compare September 12, 2026 13:40
@koistya
koistya merged commit 653b014 into main Sep 12, 2026
7 checks passed
@koistya
koistya deleted the style/oxfmt-sort-imports branch September 12, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant