Repository navigation
Preserve conditional control flow when adding braces - #382
Merged
Merged
Conversation
The default parse can see both added braces even when another symbol set sees only one. Preserve conditional headers and bodies, and keep inactive else clauses attached to their original if.
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.
Curb skips brace insertion when a conditional directive can separate the braces or change which statement an
ifcontrols. This keeps both configurations in the reported example buildable.Prompt summary: Investigate the brace insertion failure reported in #380. Fix the behavior, add regression tests, and open a pull request.
Why
A shared body can carry
#endifas leading trivia. Curb emits the opening brace before that trivia and the closing brace after the body. The default round-trip parse sees both braces, while another symbol configuration can see only the closing brace.What
Conditional headers and bodies
A brace candidate is skipped when a conditional directive falls between the start of its header and the end of its body. This covers shared bodies and headers whose closing tokens serve a different construct in another branch.
Inactive
elseclausesCurb leaves an embedded body unwrapped when a trailing inactive branch could attach an
elseto an unmatchedifinside it. The innerifcan still gain braces around its own body.Regression coverage
The tests cover both symbol settings for the reported example, deterministic reflow, a header shared with an invocation, and an inactive
else. A control case checks brace insertion for an entireifwithin one branch.Verify
dotnet run --project tests/Nullean.Curb.Tests -c Release -- --treenode-filter '/*/*/PreferBraces*/*'All 20 brace cases passed, and all six new expectations survived
dotnet format whitespace. The CLI reproduction builds under both symbol settings, and the inactiveelseexample produces2withALTdefined.Measured against the same 2,124-file generated C# corpus, both versions rewrote 2,124 files in each mode. The fix reduces the net line additions by 8 with width disabled and 10 with reflow. Output differences are confined to the new regression snippets.
Fixes #380