# Migrating Import Sorting to oxfmt 2025-12-30 We've been using the Prettier `@ianvs/prettier-plugin-sort-imports` plugin to keep imports organized. oxfmt is a new member of the Oxc family of Rust based JavaScript tools, and now ships with `experimentalSortImports`—heavily inspired by `eslint-plugin-perfectionist`—and I wanted to see if we could make the move. **Short answer: almost.** There's one blocker for monorepo setups that separate company packages from app-local imports. ## The Migration **Before** (prettier.config.js): ```js const config = { plugins: [ "@ianvs/prettier-plugin-sort-imports", "prettier-plugin-packagejson", ], importOrder: [ "", "", "", "", "^@acme/(.*)$", "", "^~/(.*)$", "", "^[./]", ], }; ``` **After** (.oxfmtrc.json): ```json { "experimentalSortImports": { "groups": [ "builtin", "external", "internal", ["parent", "sibling", "index"] ], "internalPattern": ["@acme/", "~/"], "newlinesBetween": true } } ``` The `prettier-plugin-packagejson` functionality is built-in via `experimentalSortPackageJson` (enabled by default). ## The Gotcha: Prefix Matching, Not Regex oxfmt's `internalPattern` uses **simple prefix matching**. Your regex patterns won't work: | Plugin pattern | oxfmt equivalent | |----------------|------------------| | `^@acme/(.*)$` | `@acme/` | | `^~/(.*)$` | `~/` | This is a conscious design choice. The oxfmt author [did a code search](https://github.com/search?q=%22internalPattern%3A+%5B%22&type=code) and found most real-world usage is just prefixes anyway. Fair enough. ## The "Blocker": No Custom Group Separation Here's what we can't do yet: ```js // Our current setup separates these into distinct groups: importOrder: [ "^@acme/(.*)$", // Company packages (group 1) "", "^~/(.*)$", // App-local imports (group 2) ] ``` With oxfmt, both `@acme/` and `~/` imports get squashed into a single "internal" group. They'll be sorted alphabetically together—no blank line between them. The `customGroups` feature that would fix this is [tracked in Phase 2](https://github.com/oxc-project/oxc/issues/14253), awaiting feedback. If you need this, go comment on the issue. --- ### Links - [oxfmt experimentalSortImports tracking issue](https://github.com/oxc-project/oxc/issues/14253) - [eslint-plugin-perfectionist docs](https://perfectionist.dev/rules/sort-imports) (oxfmt's inspiration) - [@ianvs/prettier-plugin-sort-imports](https://github.com/IanVS/prettier-plugin-sort-imports)