fix(autofmt): formatting idempotency for long if/else attrs, empty bodies, and split_line_attributes#5509
Open
micahkepe wants to merge 3 commits into
Open
fix(autofmt): formatting idempotency for long if/else attrs, empty bodies, and split_line_attributes#5509micahkepe wants to merge 3 commits into
micahkepe wants to merge 3 commits into
Conversation
…dies, and split_line_attributes
Three fixes for non-idempotent formatting where running the formatter
twice produces different output:
1. `write_attribute_if_chain` unconditionally inlined if/else attribute
values on one line. For long values this exceeds 80 chars, causing
ShortOptimization to oscillate. Now checks inline length against a
budget and uses a deterministic multiline layout when exceeded.
2. `write_todo_body` emitted a newline even with no comments between
braces, causing blank lines in empty component bodies. Now only
emits when actual `//` comments are found.
3. The `split_line_attributes` override forced `NoOpt` even for empty
blocks, causing `Foo {}` to expand with blank lines. Now skips the
override when the block is `Empty`.
Fixes DioxusLabs#5508
203a777 to
7434eda
Compare
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.
Five fixes for non-idempotent formatting where running the formatter
twice produces different output:
Long if/else attribute values inlined unconditionally.
write_attribute_if_chainalways wroteif cond { val } else { val }on one line. For long values (e.g. Tailwind classes) this exceeds 80
chars, causing
ShortOptimizationto oscillate. Now checks inlinelength against a budget and uses a deterministic multiline layout:
Blank lines in empty component bodies.
write_todo_bodyemitted a newline even with no comments betweenbraces. Now only emits when actual
//comments are found.split_line_attributesoverride on empty blocks.The override forced
NoOpteven forEmptyblocks (no attrs,children, or spreads), causing
Foo {}to expand with blank lines.Now skips the override when the block is
Empty.Spurious blank lines from trailing comments logic.
accumulate_full_line_commentscollected empty lines even when no//comments existed. The trailing comment paths inwrite_rsx_blockand
write_trailing_body_commentsnow check for real comments beforeemitting.
Spurious blank line in
NoOptpath for children-only blocks.Elements with children but no attributes (e.g.
li { button { ... } })got a blank line after the opening brace because
NoOptemittednew_line()for attributes then anothernew_line()before children.Now skips the extra newline when there are no attributes or spreads.
Fixes #5508
Test plan
long_if_else_attr.rsx: twoway + idempotencyempty_component_body.rsx: twoway + idempotencyempty_braces_oneliner.rsx: twoway + 3-pass idempotencyempty_braces_match_arm.rsx: 3-pass idempotencysplit_line_attributes = true:idempotent across all files after formatting