Back to all reviewers

Prefer flat control flow

ghostty-org/ghostty
Based on 2 comments
Swift

Minimize code nesting by using Swift features like `guard` statements and early returns instead of deeply nested if-else structures. When multiple code branches end with a return statement, avoid nesting with `else` clauses.

Code Style Swift

Reviewer Prompt

Minimize code nesting by using Swift features like guard statements and early returns instead of deeply nested if-else structures. When multiple code branches end with a return statement, avoid nesting with else clauses.

Instead of:

if index == count {
    return try body(accumulated)
} else {
    // More nested code here
}

Prefer:

if index == count {
    return try body(accumulated)
}
// Continue with the flow without nesting

Or consider using guard statements for early returns:

guard case .split(let c) = node else { return }
// Now work with the unwrapped variable

This approach makes code more scannable, easier to follow, and less prone to the “pyramid of doom” issue that can happen with multiple levels of nesting.

2
Comments Analyzed
Swift
Primary Language
Code Style
Category

Source Discussions