Skip to content

fix: handle lambdas in control conditions - #446

Merged
cclauss merged 2 commits into
cpplint:developfrom
janmarsino98:codex/fix-410-lambda-control-body
Jul 22, 2026
Merged

cclauss merged 2 commits into
cpplint:developfrom
janmarsino98:codex/fix-410-lambda-control-body

Conversation

@janmarsino98

@janmarsino98 janmarsino98 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #410.

The control-body check now uses CloseExpression to find the closing parenthesis of a control condition.
This prevents lambda bodies inside conditions from being mistaken for inline control bodies.

Checks: pytest with 226 passing tests, Pylint, and Mypy.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a false-positive whitespace/newline warning for control statements whose conditions contain inline lambda expressions.
    • Preserved warnings for control statements with inline brace-delimited bodies.
  • Tests

    • Added coverage verifying correct handling of lambda-containing conditions and inline control bodies.
  • Documentation

    • Updated the changelog with details of the fix.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80d836e7-4025-44c3-a0dd-f8e99bd9953f

📥 Commits

Reviewing files that changed from the base of the PR and between 400a75d and 2bd1bf2.

📒 Files selected for processing (3)
  • CHANGELOG.rst
  • cpplint.py
  • cpplint_unittest.py

📝 Walkthrough

Walkthrough

CheckBraces now separates control-condition parsing from same-line brace validation, preventing lambda-containing conditions from producing false positives. A regression test covers both accepted lambda conditions and rejected inline control bodies, and the changelog records the fix.

Changes

Lambda-aware control brace detection

Layer / File(s) Summary
Control-condition detection and regression coverage
cpplint.py, cpplint_unittest.py, CHANGELOG.rst
CheckBraces uses CloseExpression before validating same-line braces; tests cover lambda conditions and inline control bodies, and the changelog records the correction.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing lambda handling in control conditions.
Linked Issues check ✅ Passed The code and new test address the [whitespace/newline] false positive for predicates with lambdas as requested in #410.
Out of Scope Changes check ✅ Passed The changes stay focused on the lambda false-positive fix, its test, and a matching changelog note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lovewave02 lovewave02 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed this against the current develop branch and the examples in #410. The merge simulation is clean; the full suite passes with 226 tests, and pylint, mypy, and the changed-file pre-commit hooks pass. I also checked lambda conditions across if, while, for, and switch, and inline control bodies are still flagged. This looks ready to merge.

@cclauss

cclauss commented Jul 16, 2026

Copy link
Copy Markdown
Member

@aaronliu0130 Your review, please.

@androvonx95

Copy link
Copy Markdown

Checked out this branch and verified against the #410 examples plus while/for lambda conditions. False positives are gone, and inline control bodies (if / switch) are still flagged. Full idea looks sound with CloseExpression. LGTM.

@cclauss cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

RSLGTM

@cclauss
cclauss merged commit 54343dd into cpplint:develop Jul 22, 2026
6 checks passed
Comment thread cpplint_unittest.py
Comment on lines +2962 to +2966
self.TestLint(
"if (condition) { return true; }",
"Controlled statements inside brackets of if clause should be on a separate line"
" [whitespace/newline] [5]",
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This duplicates the existing tests of this pattern, but it's not big enough of a deal that I would revert it. Just be more careful next time :)

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.

[whitespace/newline] false positive with predicate

5 participants