Skip to content

Update NoNestedIfStatementsRule to flag assignment + if pattern#28

Merged
sanmai merged 5 commits intomainfrom
fix/guard-clauses-assigment
Jul 22, 2025
Merged

Update NoNestedIfStatementsRule to flag assignment + if pattern#28
sanmai merged 5 commits intomainfrom
fix/guard-clauses-assigment

Conversation

@sanmai
Copy link
Copy Markdown
Owner

@sanmai sanmai commented Jul 22, 2025

Expand the rule to detect nested if statements in two cases:

  1. Existing: if contains exactly one nested if statement
  2. New: if contains exactly one assignment followed by one if statement

This catches patterns like:

if (condition) {
    $var = getValue();
    if ($var \!== null) {
        // ...
    }
}

sanmai and others added 2 commits July 22, 2025 18:16
Expand the rule to detect nested if statements in two cases:
1. Existing: if contains exactly one nested if statement
2. New: if contains exactly one assignment followed by one if statement

This catches patterns like:
if (condition) {
    $var = getValue();
    if ($var \!== null) {
        // ...
    }
}

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're the boss! I'm just here for the yuks.

sanmai and others added 3 commits July 22, 2025 18:26
Nested if statements with elseif branches can still be converted to guard clauses:

Before:
if ($outer) {
    if ($inner) { /* A */ } elseif ($other) { /* B */ }
}

After:
if (\!$outer) return;
if ($inner) { /* A */ } elseif ($other) { /* B */ }

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

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, positively, without a doubt!

@sanmai sanmai enabled auto-merge (squash) July 22, 2025 09:48
@sanmai sanmai merged commit 741f097 into main Jul 22, 2025
16 checks passed
@sanmai sanmai deleted the fix/guard-clauses-assigment branch July 22, 2025 09:49
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