Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

Description

Sets up oxfmt (Oxc formatter) for code formatting based on oxfmt alpha release and previous attempt #945.

Changes:

  • Added oxfmt@^0.16.0 as dev dependency
  • Created .oxfmtrc.json with settings matching existing Prettier config (semi: false, singleQuote: true, printWidth: 80)
  • Enabled experimentalSortImports with partitionByNewline: true to preserve existing import groupings and minimize diff
  • Updated format script: prettier --write --cache .oxfmt
  • Updated lint-staged to use oxfmt for JS/TS/JSON files
  • Disabled eslint import-x/order and sort-imports rules since oxfmt handles import ordering now
  • Formatted all files with new formatter (most changes in packages/plugin-rsc which didn't have import sorting before)
Original prompt

setup oxfmt based on https://oxc.rs/blog/2025-12-01-oxfmt-alpha.html and past attempt #945


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Copilot AI changed the title [WIP] Setup oxfmt based on project references chore: setup oxfmt for formatting Dec 2, 2025
Copilot AI requested a review from hi-ogawa December 2, 2025 08:36
Copilot finished work on behalf of hi-ogawa December 2, 2025 08:36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Import sorting (experimentalSortImports) is intentionally not enabled based on #945 feedback—the ordering behavior (alphabetical with relative imports first) was suboptimal and caused issues with side-effect imports. Can be revisited once oxfmt improves this.

oxfmt should have improved this. Try and see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabled experimentalSortImports in commit b90e76c. The import sorting now works well - imports are grouped with newlines between groups. Also disabled the eslint import-x/order and sort-imports rules since oxfmt handles this now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot let's reduce the non-essential further by tweaking options (cf. oxc-project/oxc#14253 (comment)). For example options.partitionByNewline.

The big diff is expected only inside packages/plugin-rsc since we haven't used any sorting there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added partitionByNewline: true (with newlinesBetween: false) in commit ec6ff45. This preserves existing import groupings and reduces the diff from 265 to 105 files, with most changes now in packages/plugin-rsc as expected.

Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Copilot AI requested a review from hi-ogawa December 2, 2025 08:53
Copilot finished work on behalf of hi-ogawa December 2, 2025 08:53
Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
Copilot finished work on behalf of hi-ogawa December 2, 2025 09:06
Copy link
Member

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import sorting is way better, but still a lot of diff that could be avoided by keeping node builtins first

import tseslint from 'typescript-eslint'
import globals from 'globals'
// @ts-check
import { builtinModules } from 'node:module'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is taste but I like to keep node: module first

allowSeparatedGroups: false,
},
],
// import ordering handled by oxfmt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's delete the code instead of commented it

import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { createFilter } from 'vite'
Copy link
Member

@ArnaudBarre ArnaudBarre Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of having all type import before runtime ones, it create more diffing when switching from type import to runtime or the other way around and when importing both types and import (I personally like them to be merged) it's cleaner to have them next to each other IMO if not merged

@Dunqing
Copy link

Dunqing commented Dec 2, 2025

Maybe @leaysgur can help set up import sorting properly

@ghiscoding
Copy link

ghiscoding commented Dec 2, 2025

Maybe @leaysgur can help set up import sorting properly

I think what you guys are looking for is basically what I asked in this last comment of the same issue you referenced
oxc-project/oxc#14253 (comment)

and for that you should just add this group to your config, which first sorts (1) node:xyz, (2) then external, (3) then internal imports. The "builtin" is for NodeJS imports
"groups": ["builtin", "external"]

I'm not sure if this will ever be the default in the future (I think not), but for now the group needs be to added separately and that is what I started to use in Lerna-Lite and it's pretty much equivalent to what the plugin @ianvs/prettier-plugin-sort-imports was outputting (which is what I used before switching to oxfmt, but now it's 10x time faster 🚀)

Also please note that you should make sure to use v0.16.0 or higher since there was a fix, that was released in v0.16, for internal import detection with @/ and not @ (monorepo) in this PR oxc-project/oxc#16128

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.

5 participants