fix(formatter): should not treat multi-type arguments of TSTypeReference as a complex type#17708
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #17708 will not alter performanceComparing Summary
Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a formatter bug where type arguments in TSTypeReference were incorrectly considered complex when they contained multiple type parameters, even if none of those parameters were actually complex types. The fix ensures that Record<string, boolean> is not treated as a complex type, preventing unnecessary line breaks in formatted code.
Key changes:
- Modified the logic in
is_complex_type_argumentsto check individual type parameters instead of recursively calling itself - Added a test case demonstrating the fix with
Record<string, boolean>
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/oxc_formatter/src/utils/assignment_like.rs |
Changed the logic from recursively checking if nested type arguments are complex (which would return true for >1 params) to checking if any individual nested type parameter is a complex type |
crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts |
Added test case with Record<string, boolean> to verify non-complex multi-parameter types are handled correctly |
crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts.snap |
Updated snapshot with expected output for the new test case at different print widths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts
Show resolved
Hide resolved
crates/oxc_formatter/tests/fixtures/ts/assignments/complex-type-arguments.ts
Show resolved
Hide resolved
Merge activity
|
…nce as a complex type (#17708) **Input:** <!-- prettier-ignore --> ```tsx // Non-complex type arguments, as none of the type arguments of Record is a complex type. const result = configurationService.getValue<Record<string, boolean>>( enalementSetting ); ``` **Before output:** <!-- prettier-ignore --> ```tsx // Non-complex type arguments, as none of the type arguments of Record is a complex type. const result = configurationService.getValue< Record<string, boolean> >(enalementSetting); ``` [Prettier Playground](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAdKB6DACActAWkgFsAHAGzgA9sYBPUubAQwCcBzAV2IRgGcANCz7Yo0JhABmtABZN6jFh268RU7ACU4kVgBNsASxHNsJCtVoM4AOnSQofGNlZw+nck4C8p6JINdWZhgDaABlOFYANwMwG3Y4GAA1ZnJOOAAeLR1ddMdWAyh2IQAjCAhKZigAPiqACnRsbAQUuB5YcJhgwvQASgBuEAEQCFJg6D5kUDZWCAB3AAU2BAmUFNnmOgmh4sCwAGsE0OYeABkCuGRJFL44IYhigCttGAB1QNJkEFIXG6iL7d2BxgoVIzDABXYyBgrDSQxuxAMUJhtxA1EY+TaMBSAHl0UEIKx5hA+AYxlBPghdINUVR0QZMSkACoRKBsAyuS7XFEkwqUACKnAg8E55BuQwefCooQh-MFwqQV1FKIAjnK4PMZqQViBmHwCFA4HBdEbqdDmAZyBCAMIQYjEZifFLkak89iUACCnXyxU48HmETOBpFYpAMhgxHILxkpNcoNi4QcpIM0XonzAfC2IEiaQAklBje0wPlRu786F6JRgyjvsS4G9mB8UN9XBFIv9UfnsZJAxcUORJNSCr8YBrmOx7VWhqDWL9PsVmMU4OQCPxqd8Cq8DLoYDJkAAOAAMQxcqoMLlH44dCq5QyxxReW53yAATENODdGQuVoqQ61F7pjV0E5Ki4Mc4AAMQJe1OghR1fQgEAAF9EKAA) **After output:** <!-- prettier-ignore --> ```tsx // Non-complex type arguments, as none of the type arguments of Record is a complex type. const result = configurationService.getValue<Record<string, boolean>>(enalementSetting); ```
90c6356 to
3b4aced
Compare
# Oxlint # Oxfmt ### 🚀 Features - a19cc93 oxfmt: Add debug logging to oxfmt LSP to troubleshoot resolved options at runtime (#17695) (Nicholas Rayburn) ### 🐛 Bug Fixes - 3b4aced formatter: Should not treat multi-type arguments of TSTypeReference as a complex type (#17708) (Dunqing) - dcfdd41 formatter: Should not set up tailwindcss callback when no tailwindcss configuration is set (#17696) (Dunqing) - 6f65901 formatter: Return original classes when there are no tailwindcss classes sort callback (#17689) (Dunqing) ### ⚡ Performance - c6a99fd formatter: Don't call `sort_tailwind_classes` if no classes need to be sorted (#17698) (Dunqing) Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>

Input:
Before output:
Prettier Playground
After output: