-
-
Notifications
You must be signed in to change notification settings - Fork 721
fix(oxfmt): Handle .d.ts file correctly
#14835
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
fix(oxfmt): Handle .d.ts file correctly
#14835
Conversation
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.
Pull Request Overview
This PR fixes the handling of .d.ts (TypeScript declaration) files in the oxfmt formatter. The key change is switching from extension-based detection to path-based detection to properly recognize .d.ts files, which have a compound extension.
- Changed
SourceType::from_extension()toSourceType::from_path()to correctly detect.d.tsfiles - Added test coverage for
.d.tsfiles and glob pattern exclusions - Added multiple test fixture files to verify formatting behavior across different file types
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_formatter/src/service/source_type.rs | Switched from extension-based to path-based source type detection to handle .d.ts files correctly |
| apps/oxfmt/tests/mod.rs | Added test case for glob pattern exclusion of TypeScript files |
| apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap.new | Updated test snapshot to include .d.ts file and new glob exclusion test case |
| apps/oxfmt/tests/fixtures/multiple_files/simple.ts | Added new TypeScript test fixture with formatting issues |
| apps/oxfmt/tests/fixtures/multiple_files/component.jsx | Added new JSX test fixture with formatting issues |
| apps/oxfmt/tests/fixtures/multiple_files/arrow.js | Updated JavaScript test fixture content from arrow functions to JSX element |
| apps/oxfmt/tests/fixtures/multiple_files/app.tsx | Added new TSX test fixture with formatting issues |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
31b5c05 to
a0e70f2
Compare
.d.ts file correctly
CodSpeed Performance ReportMerging #14835 will not alter performanceComparing Summary
Footnotes
|
Merge activity
|
> #14803 (comment) `.d.ts` was parsed as `.ts` by `path.extension()`.
a0e70f2 to
7a420a1
Compare
## [0.7.0] - 2025-10-21 ### 🚀 Features - 6dfcd80 oxfmt: Search both .json and .jsonc config file (#14848) (leaysgur) - aa024d9 formatter: Wrap parenthesis for `AssignmentExpression` that are inside `ComputedMemberExpression` (#14834) (Dunqing) ### 🐛 Bug Fixes - 88fb768 formatter: Correct handling of ignore comment for `TSUnionType` and `TSMappedType` (#14824) (Dunqing) - f7727c7 formatter: Ignore comment doesn't work for the expression statement (#14817) (Dunqing) - 7a420a1 oxfmt: Handle `.d.ts` file correctly (#14835) (leaysgur) ### 🚜 Refactor - 6fa7420 oxfmt: Use custom ignore builder (#14850) (leaysgur) - 9d914a3 formatter: Improve comments handling (#14816) (Dunqing) - f52863d formatter: Improve handling of type cast node (#14815) (Dunqing)

.d.tswas parsed as.tsbypath.extension().