Skip to content

fix: allow braces after multiline preprocessor directives - #480

Open
PNHD wants to merge 2 commits into
cpplint:developfrom
PNHD:fix/294-multiline-preprocessor-braces
Open

PNHD wants to merge 2 commits into
cpplint:developfrom
PNHD:fix/294-multiline-preprocessor-braces

Conversation

@PNHD

@PNHD PNHD commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

A brace on its own line is allowed after a preprocessor directive, but the check only looks at its last physical line. Splitting an OpenMP pragma with a backslash therefore produces a whitespace/braces warning.

Follow line continuations back to the start of the directive. The other checks still use the original preceding line. Regression cases cover two- and three-line pragmas, comments and blank lines, and ordinary code that must continue to warn.

Fixes #294.

Validation: 238 tests passed with 96.47% coverage on Python 3.12; Ruff check/format, pylint, and mypy passed. The new regression cases fail on the base revision and pass with the fix.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed false-positive brace-placement warnings when an opening brace follows a multiline preprocessor directive, including continued OpenMP directives and directives with trailing comments or intervening blank lines.
    • Brace-placement checks continue to apply to regular code after a directive, such as an if statement, so the exception does not hide unrelated warnings.

Trace continued lines to their directive before applying the standalone brace warning. Preserve the existing checks for ordinary continued code.

Fixes cpplint#294.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

CheckBraces now follows backslash-continued lines to check whether the preceding line starts a preprocessor directive. Tests cover braces after directives and ordinary code that must still produce a brace-placement warning.

Changes: Brace handling after directives

Layer / File(s) Summary
Directive continuation handling and validation
cpplint.py, cpplint_unittest.py, CHANGELOG.rst
CheckBraces follows continued lines to identify preprocessor directives. Tests cover single-line and continued directives, comments and blank lines, and ordinary code after directives. The changelog records the fix.

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: csq57, cclauss

Merge Risk: Minimal · up to 98ad3

The change stops spurious whitespace/braces warnings for a brace after a multi-line preprocessor directive, as issue #294 requests. Ordinary code keeps its warning. A rare case remains where a block comment sits inside a continued pragma, and it behaves as before. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: allow braces after multiline preprocessor directives" matches the main change. The PR changes CheckBraces so that a brace on its own line after a backslash-continued preprocessor direc…
Linked Issues check Passed Directly linked issue #294 requires that a brace on its own line after a backslash-continued OpenMP pragma not trigger whitespace/braces. The whole-PR summary states that CheckBraces now uses the line…
Out of Scope Changes check Passed The summary lists three changed files. cpplint.py contains the CheckBraces change for #294. cpplint_unittest.py adds parameterized regression tests for braces after OpenMP pragmas and for code that mu…
Full details: Title check

Explanation

The title "fix: allow braces after multiline preprocessor directives" matches the main change. The PR changes CheckBraces so that a brace on its own line after a backslash-continued preprocessor directive no longer triggers whitespace/braces. The changelog, the cpplint.py logic change, and the new regression tests all support this. The title is concise, specific, and follows a conventional commit style.

Full details: Linked Issues check

Explanation

Directly linked issue #294 requires that a brace on its own line after a backslash-continued OpenMP pragma not trigger whitespace/braces. The whole-PR summary states that CheckBraces now uses the line returned by GetPreviousNonBlankLine, follows backslash continuations through clean_lines.raw_lines to the directive start, and exempts the brace when that start matches '#'. The PR description and the test summary cover two- and three-line pragmas, comments and blank lines, and ordinary code that must still warn. This behavior matches the issue. Limitation: the diff tool was unavailable for the base-to-head and previous-to-head ranges, and the file read could not be targeted to CheckBraces. The PASS rests on the whole-PR summary and PR description. The head changed from d3f4003 to 98ad3db since the previous review, and the content of that incremental change could not be read. The summary of the whole PR describes the same behavior.

Full details: Out of Scope Changes check

Explanation

The summary lists three changed files. cpplint.py contains the CheckBraces change for #294. cpplint_unittest.py adds parameterized regression tests for braces after OpenMP pragmas and for code that must still warn. CHANGELOG.rst adds one entry that references #294. All changes connect to #294. The optional merge commit described in the comments is on a separate branch and is not part of this PR's listed changes. Limitation: the diff tool was unavailable, so the file list and line counts come from the AI-generated summary and could not be checked against the diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d76a914d-e814-4d97-85f7-5872b649946f
Commits

Reviewing files that changed from the base of the PR and between d3f4003 and 98ad3db.

Files selected for processing: 3

  • CHANGELOG.rst
  • cpplint.py
  • cpplint_unittest.py
Files skipped from review as they are similar to previous changes: 1

  • CHANGELOG.rst

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@Csq57 Csq57 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I independently reviewed PR #480 at pinned head d3f4003 against develop (926bf4b), using GitHub-hosted Ubuntu, Windows, and macOS with Python 3.12 and 3.15.1 (pytest==9.1.1).

Full-suite comparison (consistent across all three operating systems):

Source | Python 3.12 | Python 3.15.1 -- | -- | -- Base develop | 231 passed | 227 passed, 4 failed PR #480 | 238 passed | 234 passed, 4 failed

I also ran independent CheckBraces reproductions. Two- and three-line OpenMP directives produce the unwanted whitespace/braces warning on the base but not on this PR. Single-line pragmas remain unaffected, while ordinary if statements, continued if conditions, and separate if statements following pragmas still report the expected warning.

The four Python 3.15.1 failures are identical on the base and PR branches and involve the existing os.path.commonprefix() deprecation warnings. They are unrelated to this PR's changes.

One non-blocking observation: the continuation logic also exempts braces following multiline #define directives. This appears consistent with the checker's existing exemption for immediately preceding preprocessor directives, but an additional regression test could document the intended behavior.

Independent evidence:
https://github.com/Csq57/ai-python-repository-stabilization-case-study/actions/runs/40453763938

The comparison workflow passed, but the Python 3.15.1 pytest runs themselves retained their four known failures.

This review was prepared with AI assistance and grounded in actual independent CI executions.

Approved for the scoped Issue #294 fix based on the tested head.

DanceoftheAurora added a commit to DanceoftheAurora/cpplint that referenced this pull request Nov 6, 2026
@DanceoftheAurora

Copy link
Copy Markdown

I checked the current merge conflict and prepared an optional merge commit on this branch, with parents d3f4003 (this PR) and 880b36e (current develop).

Only CHANGELOG.rst needed manual resolution; it retains both the #294 and #445 entries. The source and tests merged automatically, and the resulting diff against develop preserves this PR's original changes. Locally, 248 tests passed with 96.67% coverage, along with configured Pylint, Mypy, applicable pre-commit hooks and 16 multiline-preprocessor behavior cases. Prepared with AI assistance and independently checked; remote CI has not been run on this merge commit. This is available if it saves you the merge-resolution work.

…e-preprocessor-braces

# Conflicts:
#	CHANGELOG.rst

This branch has not been deployed

No deployments
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.

Disable whitespace/braces for blocks after multi-line OpenMP directives

3 participants