Skip to content

fix(autofmt): remove extra whitespace before commas in for-loop tuple patterns#5384

Open
costajohnt wants to merge 2 commits intoDioxusLabs:mainfrom
costajohnt:fix/fmt-forloop-tuple-whitespace
Open

fix(autofmt): remove extra whitespace before commas in for-loop tuple patterns#5384
costajohnt wants to merge 2 commits intoDioxusLabs:mainfrom
costajohnt:fix/fmt-forloop-tuple-whitespace

Conversation

@costajohnt
Copy link
Contributor

Summary

Fixes #5348

dx fmt was adding extra spaces before commas in for-loop tuple destructuring patterns:

// Before (incorrect)
for (index , name , value) in data.iter() {

// After (correct)
for (index, name, value) in data.iter() {

The root cause was that forloop.pat.clone().into_token_stream() uses proc_macro2::TokenStream::Display, which inserts a space between every token including before commas in tuple patterns.

The fix adds an unparse_pat helper that routes the pattern through prettyplease for proper formatting, following the existing unparse_expr pattern.

Test plan

  • Added forloop_tuple.rsx sample test covering 3-element tuple, simple ident, 2-element tuple, and wildcard patterns
  • All 69 dioxus-autofmt tests pass
  • Existing ifchain_forloop test continues to pass (simple for i in b regression)

… patterns

`dx fmt` was adding spaces before commas in for-loop destructuring
patterns (e.g. `for (index , name , value)`) because `TokenStream::Display`
inserts spaces between every token. Route the pattern through prettyplease
via a new `unparse_pat` helper, following the existing `unparse_expr` pattern.

Fixes DioxusLabs#5348
@costajohnt costajohnt marked this pull request as ready for review March 17, 2026 23:34
@costajohnt costajohnt requested a review from a team as a code owner March 17, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dx fmt adds extra whitespaces in a forloop

1 participant