Fix formatting of long template parameter declarations - #11838
Draft
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
Draft
Fix formatting of long template parameter declarations#11838Timothee Guerin (timotheeguerin) wants to merge 3 commits into
Timothee Guerin (timotheeguerin) wants to merge 3 commits into
Conversation
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Timothee Guerin (timotheeguerin)
added a commit
to timotheeguerin/azure-rest-api-specs
that referenced
this pull request
Sep 2, 2026
…arations Preview of the effect of microsoft/typespec#11838
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11836
A template parameter list with a single parameter was always "hugged", so it could never break. When the declaration got too long the constraint (or default) was split instead, leaving the
>stranded in the middle of the line:Now a single parameter is only hugged when it cannot break by itself. As soon as it has a breakable constraint or default, the parameter list breaks instead — like prettier does for TypeScript type parameters — and the union only splits when it still doesn't fit:
Parameters that cannot break (
<T>,<T extends TypeSpec.Reflection.Model>,<T = Foo>) keep hugging exactly as before, even when the line ends up over the print width, so existing specs are not reflowed for no reason.The issue was not specific to
op ... is: it applied to every construct that can declare template parameters —model(is/extends/body),alias,interface, ops inside an interface,unionandscalar. All of them are covered by the new tests.Template arguments are untouched, so the behavior from #11009 / #11092 (
Foo<{...}>and long single unions staying attached to the reference) is unchanged.Along the way this surfaced a small wart in the one place TypeSpec inlines a model expression — properties are now separated by
;instead of;:Impact
Reformatting all 5054
.tspfiles inAzure/azure-rest-api-specswith the current formatter changes 0 files; with this fix it changes 6, and every hunk is the broken shape above being repaired — preview PR.