-
-
Notifications
You must be signed in to change notification settings - Fork 210
chore: setup oxfmt for formatting #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com>
ArnaudBarre
left a comment
There was a problem hiding this 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' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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
|
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 and for that you should just add this group to your config, which first sorts (1) 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 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 |
Description
Sets up oxfmt (Oxc formatter) for code formatting based on oxfmt alpha release and previous attempt #945.
Changes:
oxfmt@^0.16.0as dev dependency.oxfmtrc.jsonwith settings matching existing Prettier config (semi: false,singleQuote: true,printWidth: 80)experimentalSortImportswithpartitionByNewline: trueto preserve existing import groupings and minimize diffformatscript:prettier --write --cache .→oxfmtlint-stagedto useoxfmtfor JS/TS/JSON filesimport-x/orderandsort-importsrules since oxfmt handles import ordering nowpackages/plugin-rscwhich didn't have import sorting before)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.