Skip to content

feat: add whenNeeded and whenFormattedMultiLine brace modes#7

Open
steffen-heil-secforge wants to merge 1 commit intomainfrom
feature/use-braces-modes
Open

feat: add whenNeeded and whenFormattedMultiLine brace modes#7
steffen-heil-secforge wants to merge 1 commit intomainfrom
feature/use-braces-modes

Conversation

@steffen-heil-secforge
Copy link
Member

@steffen-heil-secforge steffen-heil-secforge commented Oct 24, 2025

This commit introduces two new brace usage modes for control flow statements: whenNeeded and whenFormattedMultiLine, providing more granular control over brace insertion.

Added enum variants

UseBraces::WhenNeeded: Only uses braces when syntactically required (empty blocks, declarations, multiple statements, or to avoid dangling else ambiguity)

UseBraces::WhenFormattedMultiLine: Uses braces when the formatted body spans multiple lines, removing them for single-line statements

Implementation changes

  • Replaced force_use_braces_for_stmt with more flexible helper functions (get_use_braces_for_node, get_use_braces_for_stmt)
  • Added contains_dangling_if to detect dangling else problems
  • Added use_braces_for_then and use_braces_for_else to enforce braces when required for correctness (declarations, dangling else)
  • Updated gen_conditional_brace_body to support new brace modes
  • Updated gen_if_stmt to intelligently apply braces based on context

Test coverage

  • Added 13 test files covering whenNeeded and whenFormattedMultiLine modes
  • All 660 spec tests passing

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/use-braces-modes branch 2 times, most recently from 7ebd588 to bd26b84 Compare October 27, 2025 14:44
@steffen-heil-secforge steffen-heil-secforge changed the title feat: add useBraces modes and fix nextControlFlowPosition edge cases feat: add whenNeeded and whenFormattedMultiLine brace modes Oct 27, 2025
This commit introduces two new brace usage modes for control flow statements: whenNeeded and whenFormattedMultiLine, providing more granular control over brace insertion.

Added enum variants:

UseBraces::WhenNeeded: Only uses braces when syntactically required (empty blocks, declarations, multiple statements, or to avoid dangling else ambiguity)
UseBraces::WhenFormattedMultiLine: Uses braces when the formatted body spans multiple lines, removing them for single-line statements

Implementation changes:

Replaced force_use_braces_for_stmt with more flexible helper functions (get_use_braces_for_node, get_use_braces_for_stmt)
Added contains_dangling_if to detect dangling else problems
Added use_braces_for_then and use_braces_for_else to enforce braces when required for correctness (declarations, dangling else)
Updated gen_conditional_brace_body to support new brace modes
Updated gen_if_stmt to intelligently apply braces based on context

Test coverage:

Added 13 test files covering whenNeeded and whenFormattedMultiLine modes
All 660 spec tests passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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