feat(formatter): support custom internal import patterns#16322
feat(formatter): support custom internal import patterns#16322relsunkaev wants to merge 1 commit intooxc-project:mainfrom
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
There was a problem hiding this comment.
Pull request overview
This pull request adds support for custom internal import patterns in the formatter's experimental import sorting feature. It allows users to configure patterns (e.g., "@company/", "pkg-") via .oxfmtrc's experimentalSortImports.internalPattern field to classify imports as "internal" when sorting. The implementation includes configuration validation, NAPI playground integration, and comprehensive end-to-end tests.
Key changes:
- Added
internalPatternconfiguration option accepting single string or array of strings in JSON schema and config files - Implemented prefix-based pattern matching with optional trailing
*support (e.g.,@acme/*becomes@acme/prefix matcher) - Added ES2025
RegExp.escapepolyfill for test utilities to handle special characters in path normalization
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
npm/oxfmt/configuration_schema.json |
Added internalPattern and StringOrStringArray schema definitions for import sorting configuration |
napi/playground/src/options.rs |
Added internal_pattern field to OxcSortImportsOptions accepting string or array of strings |
napi/playground/src/lib.rs |
Implemented conversion logic from NAPI options to internal patterns with error handling |
napi/playground/index.d.ts |
Added TypeScript type definition for internalPattern option |
crates/oxc_formatter/tests/snapshots/schema_json.snap |
Updated snapshot with new schema definitions |
crates/oxc_formatter/src/service/oxfmtrc.rs |
Added deserialization, validation, and normalization for internalPattern config with comprehensive tests |
crates/oxc_formatter/src/options.rs |
Implemented InternalImportPattern struct with prefix-based matching logic and unit tests |
crates/oxc_formatter/src/lib.rs |
Exported normalize_internal_pattern_value for NAPI integration |
crates/oxc_formatter/src/ir_transform/sort_imports/compute_metadata.rs |
Integrated internal pattern matching into import path classification logic |
crates/oxc_formatter/examples/sort_imports.rs |
Updated example to initialize new internal_patterns field |
apps/oxfmt/test/utils.ts |
Added RegExp.escape polyfill for ES2025 compatibility in path normalization |
apps/oxfmt/test/sort_imports_internal_pattern.test.ts |
Added end-to-end tests for internal pattern configuration |
apps/oxfmt/test/fixtures/sort_imports_internal_pattern/* |
Added test fixtures for monorepo patterns and literal asterisk handling |
apps/oxfmt/test/__snapshots__/sort_imports_internal_pattern.test.ts.snap |
Added snapshots verifying correct import sorting with internal patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot These fixture files are intentional inputs for the write-mode snapshot tests—the imports are the actual content we run through oxfmt, so they are expected to be unused in the fixture itself. |
|
@copilot Clarified how the trailing works per your suggestion. Thanks! |
7d3821e to
93b5a9d
Compare
|
I think it's duplicate with #16372 |
|
Oops, thanks for the PR and for your interest in the project! Unfortunately, I've already been working on this same feature myself, so I won't be able to merge this... Sorry for the overlap! 🙏🏻 For next time, feel free to open or comment an issue first — that way we can check if something's already in progress and avoid stepping on each other's toes. I appreciate the effort, and hope to see you around the project again! |
|
All good! Just glad this is getting implemented |
Summary
.oxfmtrcexperimentalSortImports.internalPatternby parsing prefixes once in the formatter core, validating config input, and surfacing the option through the NAPI playground + schema docsTesting