refactor(formatter): SortImportsTransform::transform return Vec not Option<Vec>#22073
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. |
SortImportsTransform::transform return Vec not Option<Vec>`SortImportsTransform::transform return Vec not Option<Vec>
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the formatter’s import-sorting IR transform to remove an unreachable empty-input branch introduced for the legacy whole-document case. Since import sorting is now driven on streaming “import chunks” (post-#22065) that always contain at least one ImportDeclaration, SortImportsTransform::transform no longer needs to return Option.
Changes:
- Change
SortImportsTransform::transformto returnArenaVec<FormatElement>instead ofOption<ArenaVec<...>>. - Simplify
sort_imports_chunkby removing the unreachableNonehandling and always splicing the sorted output back into the buffer. - Add a
debug_assert!that the transform output ends with the synthesizedLine(Hard)terminator.
b7045ab to
f539758
Compare
331ffe6 to
c744bdd
Compare
c744bdd to
2fd907d
Compare
f539758 to
801f277
Compare
801f277 to
51ec2d4
Compare
Merge activity
|
…ot `Option<Vec>` (#22073) After #22065, the "return `None` if empty file" case can never fire, since it's only ever called with a segment of IR containing at least one `ImportDeclaration`. So remove the check, and make `transform` return `Vec<FormatElement>`, instead of `Option<Vec<FormatElement>>`.
51ec2d4 to
5de13ff
Compare

After #22065, the "return
Noneif empty file" case can never fire, since it's only ever called with a segment of IR containing at least oneImportDeclaration. So remove the check, and maketransformreturnVec<FormatElement>, instead ofOption<Vec<FormatElement>>.