Skip to content

Add --force_curly_braces option to insert braces around single-statem…#614

Open
burner wants to merge 1 commit intodlang-community:masterfrom
burner:forced_braces
Open

Add --force_curly_braces option to insert braces around single-statem…#614
burner wants to merge 1 commit intodlang-community:masterfrom
burner:forced_braces

Conversation

@burner
Copy link

@burner burner commented Feb 17, 2026

…ent bodies.

When enabled, the preprocessor inserts synthetic { and } tokens around braceless bodies for all block header constructs: if, else, for, foreach, while, do, scope, synchronized, with, catch, debug, version, finally, and their combinations (static if, static foreach, etc.). Implementation uses token stream preprocessing so the formatter's existing brace-handling logic handles style and indentation naturally. Synthetic tokens use size_t.max-based indices to avoid collisions with AST info lookups. Handles compound constructs correctly:

  • try/catch/finally chains as single statements
  • Nested braceless blocks (each level gets its own braces)
  • Mixed braced/braceless siblings (only braceless branches get braces)
  • else if/else version/else static if chains (no double-wrapping)
  • debug/version with and without parens
  • Respects // dfmt off / // dfmt on regions

…ent bodies.

When enabled, the preprocessor inserts synthetic `{` and `}` tokens around
braceless bodies for all block header constructs: if, else, for, foreach,
while, do, scope, synchronized, with, catch, debug, version, finally, and
their combinations (static if, static foreach, etc.).
Implementation uses token stream preprocessing so the formatter's existing
brace-handling logic handles style and indentation naturally. Synthetic tokens
use size_t.max-based indices to avoid collisions with AST info lookups.
Handles compound constructs correctly:
- try/catch/finally chains as single statements
- Nested braceless blocks (each level gets its own braces)
- Mixed braced/braceless siblings (only braceless branches get braces)
- else if/else version/else static if chains (no double-wrapping)
- debug/version with and without parens
- Respects // dfmt off / // dfmt on regions
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.

1 participant

Comments