feat(oxfmt/sort-imports): support custom groups#17576
feat(oxfmt/sort-imports): support custom groups#17576leaysgur merged 24 commits intooxc-project:mainfrom
Conversation
00ea51b to
c405a09
Compare
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Thank you~. Great work! 👏🏻 I'll review the changes and go through from now.
If possible, could you submit a separate PR for these? |
crates/oxc_formatter/src/ir_transform/sort_imports/compute_metadata.rs
Outdated
Show resolved
Hide resolved
crates/oxc_formatter/src/ir_transform/sort_imports/compute_metadata.rs
Outdated
Show resolved
Hide resolved
crates/oxc_formatter/src/ir_transform/sort_imports/group_config.rs
Outdated
Show resolved
Hide resolved
f74914b to
73ff4ab
Compare
This comment was marked as resolved.
This comment was marked as resolved.
leaysgur
left a comment
There was a problem hiding this comment.
Thanks again. ✨
Actually, index-type and sibling-type are invalid groups in perfectionist.
OK, let's remove it.
Regarding this, I'll leave it up to you whether to address it in this PR or create a separate one.
crates/oxc_formatter/src/ir_transform/sort_imports/compute_metadata.rs
Outdated
Show resolved
Hide resolved
73ff4ab to
1a3d3de
Compare
|
NOTE:
|
Preparation for #17576 ``` error: large size difference between variants --> apps/oxfmt/src/core/config.rs:51:1 | 51 | / pub enum ResolvedOptions { 52 | | /// For JS/TS files formatted by oxc_formatter. 53 | | / OxcFormatter { 54 | | | format_options: FormatOptions, 55 | | | /// For embedded language formatting (e.g., CSS in template literals) 56 | | | external_options: Value, 57 | | | insert_final_newline: bool, 58 | | | }, | | |_____- the largest variant contains at least 281 bytes ... | 66 | | / ExternalFormatterPackageJson { 67 | | | external_options: Value, 68 | | | sort_package_json: Option<sort_package_json::SortOptions>, 69 | | | insert_final_newline: bool, 70 | | | }, | | |_____- the second-largest variant contains at least 75 bytes 71 | | } | |___^ the entire enum is at least 288 bytes | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#large_enum_variant = note: `-D clippy::large-enum-variant` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]` help: consider boxing the large fields or introducing indirection in some other way to reduce the total size of the enum | 54 - format_options: FormatOptions, 54 + format_options: Box<FormatOptions>, | ```
1a3d3de to
0f369cd
Compare
bb9fef7 to
8381619
Compare
|
Many tests involving |
|
Thanks again! About their tests, everything is as expected, and since we've been modifying and porting test cases all along. 😅 So, it should be fine for now. I plan to review it again tomorrow morning and merge it. 👍🏻 |
#17076
Authorship & Use of AI
All code changes in this pull request are completed by a human (myself).
ChatGPT is used only to assist with writing comments and this PR description.
Commit Structure
The changes are split into small, meaningful commits.
Each commit should be reviewable independently.
Current State of the Implementation
For easier comparison, I forked actual and made a few auxiliary changes on a separate branch nilptr/feat/oxfmt-custom-groups.
The auxiliary changes include:
oxfmtto address the incompatible binding API.eslint.config.mjsto lint and fix .ts files..oxfmtrcto enableexperimentalSortImports, keeping it consistent witheslint.config.mjs.How to Compare?
Clone
git@github.com:nilptr/actual.gitand check outnilptr/feat/oxfmt-custom-groupsbranch.Run
yarn installRun
NAPI_RS_NATIVE_LIBRARY_PATH=/path/to/binding.node yarn fmt:oxfmtThe native binding can be obtained in one of the following ways:
pnpm build, and locate the .node binding file underapps/oxfmt/src-js.Inspect the results with
git diff— the diff shows the differences between perfectionist and oxfmtObserved Differences
There are 9 differences in total:
experimentalSortImports. (be the way, they are introduced after I rebased main branch)experimentalSortImports, but are not caused by the group-matching logic, which is the focus of this PR.ImportLineMetadata.sourceI believe we can start review now.
While the review is ongoing, I will also try to see whether the observed differences can be fixed in this PR.