feat: add nextLineExceptAfterBrace control flow position option#8
Open
steffen-heil-secforge wants to merge 1 commit intomainfrom
Open
feat: add nextLineExceptAfterBrace control flow position option#8steffen-heil-secforge wants to merge 1 commit intomainfrom
steffen-heil-secforge wants to merge 1 commit intomainfrom
Conversation
d272e43 to
8218e02
Compare
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>
d9ea398 to
76ddb86
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.
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.,} elsestays together, butstatement; elsegets separated)Changes: