Migrating Import Sorting to oxfmt

December 30, 2025

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):

const config = {
  plugins: [
    "@ianvs/prettier-plugin-sort-imports",
    "prettier-plugin-packagejson",
  ],
  importOrder: [
    "<BUILT_IN_MODULES>",
    "",
    "<THIRD_PARTY_MODULES>",
    "",
    "^@acme/(.*)$",
    "",
    "^~/(.*)$",
    "",
    "^[./]",
  ],
};

After (.oxfmtrc.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 patternoxfmt equivalent
^@acme/(.*)$@acme/
^~/(.*)$~/

This is a conscious design choice. The oxfmt author did a code search 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:

// 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, awaiting feedback. If you need this, go comment on the issue.


Links

Comments 0

No comments yet. Be the first to comment!