Skip to content

feat: add nextLineExceptAfterBrace control flow position option#8

Open
steffen-heil-secforge wants to merge 1 commit intomainfrom
feature/next-line-except-after-brace
Open

feat: add nextLineExceptAfterBrace control flow position option#8
steffen-heil-secforge wants to merge 1 commit intomainfrom
feature/next-line-except-after-brace

Conversation

@steffen-heil-secforge
Copy link
Member

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

This commit adds a new NextControlFlowPosition option that forces the next control flow (else, catch, finally, while) to be on the next line, except when it appears after a closing brace.

This is useful for consistent control flow positioning, particularly when using configurations that may remove braces conditionally. It ensures that control flow keywords appear on a new line when following non-braced statements, but remain on the same line when following braced blocks.

Options:

  • nextLineExceptAfterBrace: Forces next control flow to new line, except when preceded by a closing brace (e.g., } else stays together, but statement; else gets separated)

Changes:

  • Added NextLineExceptAfterBrace variant to NextControlFlowPosition enum
  • Updated schema.json with new configuration option
  • Modified gen_control_flow_separator to handle the new positioning mode
  • Added handle_else_after_brace_removal helper for Maintain mode
  • Added push_always_true_condition helper for brace tracking
  • Updated gen_do_while_stmt to track brace presence
  • Updated gen_try_stmt to track brace presence for catch/finally
  • Added 4 test cases covering do-while and try-catch-finally scenarios

@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/next-line-except-after-brace branch 3 times, most recently from d272e43 to 8218e02 Compare October 27, 2025 07:02
@steffen-heil-secforge steffen-heil-secforge changed the title feat: Add nextLineExceptAfterBrace control flow position option feat: add nextLineExceptAfterBrace control flow position option Oct 27, 2025
Add new control flow positioning option that keeps keywords on same line after
closing braces, but moves to next line when braces are removed or when trailing
comments are present. This provides better formatting for control flow statements
like if-else, try-catch-finally, and do-while.

Behavior:
- `if (x) { f(); } else { g(); }` → keeps else on same line
- `if (x) f(); else g();` → moves else to next line (no braces)
- `if (x) { f(); } // comment\nelse { g(); }` → moves else to next line (trailing comment)
- Empty blocks stay compact: `try {} catch {}` stays on same line
- Works with all control flow: if-else, try-catch-finally, do-while

Configuration:
- `ifStatement.nextControlFlowPosition: "nextLineExceptAfterBrace"`
- `tryStatement.nextControlFlowPosition: "nextLineExceptAfterBrace"`
- `doWhileStatement.nextControlFlowPosition: "nextLineExceptAfterBrace"`

Fixes:
- Empty single-line blocks now stay compact instead of expanding
- Fixed SameLine mode bug where empty blocks incorrectly forced newlines

Tests:
- Added 69 new test cases covering all scenarios
- Added separate ASI test files following existing patterns
- All 654 tests passing

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

Co-Authored-By: Claude <noreply@anthropic.com>
@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/next-line-except-after-brace branch from d9ea398 to 76ddb86 Compare October 30, 2025 09:59
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