Skip to content

fix(pre-commit): normalize SPDX handling#3081

Open
bdice wants to merge 1 commit into
NVIDIA:mainfrom
bdice:normalize-spdx-pre-commit
Open

fix(pre-commit): normalize SPDX handling#3081
bdice wants to merge 1 commit into
NVIDIA:mainfrom
bdice:normalize-spdx-pre-commit

Conversation

@bdice

@bdice bdice commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Contributes to rapidsai/build-planning#303.

Standardizes clang-format's SPDX protection and ensures the repository uses rapidsai/pre-commit-hooks v1.6.0. It also restores malformed SPDX headers where present.

Validated with pre-commit run --all-files.

Signed-off-by: Bradley Dice <bdice@bradleydice.com>
@bdice bdice added bug Something isn't working non-breaking Non-breaking change labels Jul 10, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@bdice bdice marked this pull request as ready for review July 11, 2026 00:58
@bdice bdice requested a review from a team as a code owner July 11, 2026 00:58
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Style
    • Updated formatting rules for recognized comment pragmas.
    • Adjusted handling of IWYU and SPDX comment markers during code formatting.

Walkthrough

Changes

Clang-format configuration

Layer / File(s) Summary
Simplify pragma matching
cpp/.clang-format
The CommentPragmas regex now directly matches IWYU pragma: and SPDX- markers.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the SPDX handling normalization change in clang-format.
Description check ✅ Passed The description is related to the SPDX and pre-commit changes described in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/.clang-format`:
- Line 59: Update the CommentPragmas regex in the clang-format configuration to
anchor both recognized pragmas at the start of the comment text, preserving the
existing IWYU pragma and SPDX matches while preventing incidental prose from
being treated as a pragma.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c8113cb7-4cf1-426d-9764-e0ecee927503

📥 Commits

Reviewing files that changed from the base of the PR and between 99ca825 and 3e27bda.

📒 Files selected for processing (1)
  • cpp/.clang-format

Comment thread cpp/.clang-format
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ ?[*]? ?(IWYU pragma:|SPDX-)'
CommentPragmas: '(IWYU pragma:|SPDX-)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp=$(mktemp --suffix=.cc)
trap 'rm -f "$tmp"' EXIT

cat >"$tmp" <<'EOF'
/* This ordinary comment mentions SPDX- in prose and should remain reflowable. */
void f();
EOF

clang-format --version
clang-format -style=file -assume-filename=cpp/comment-pragmas.cc "$tmp"

Repository: NVIDIA/raft

Length of output: 200


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '--- cpp/.clang-format ---\n'
sed -n '1,120p' cpp/.clang-format

printf '\n--- references to CommentPragmas / clang-format ---\n'
rg -n "CommentPragmas|clang-format|-style=file" -S . --glob '!**/.git/**'

Repository: NVIDIA/raft

Length of output: 240


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

python3 - <<'PY'
import re
samples = [
    "/* This ordinary comment mentions SPDX- in prose and should remain reflowable. */",
    "// SPDX-123",
    "// This documents SPDX- headers",
    "/* IWYU pragma: keep */",
    "/* note: IWYU pragma: keep in prose */",
]

patterns = {
    "unanchored": r"(IWYU pragma:|SPDX-)",
    "anchored_original": r"^(IWYU pragma:|SPDX-)",
    "proposed": r"^ *[*]? *(IWYU pragma:|SPDX-)",
}

for name, pat in patterns.items():
    rx = re.compile(pat)
    print(f"[{name}] {pat}")
    for s in samples:
        print(f"  {bool(rx.search(s))}  {s}")
    print()
PY

Repository: NVIDIA/raft

Length of output: 966


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '--- cpp/.clang-format ---\n'
cat -n cpp/.clang-format | sed -n '1,120p'

printf '\n--- references to CommentPragmas / clang-format ---\n'
rg -n "CommentPragmas|clang-format|-style=file" -S . --glob '!**/.git/**'

Repository: NVIDIA/raft

Length of output: 240


🌐 Web query:

clang-format CommentPragmas regex matched against comment text leading // stripped before matching

💡 Result:

In clang-format, the CommentPragmas regular expression is matched against the text of the comment after the leading comment markers (such as // or /*) and any associated whitespace have been stripped [1][2]. When clang-format processes comments, it uses the CommentPragmas regex to identify lines that should not be reflowed or split into multiple lines [3][4][5]. The source code implementation of the breakable token logic indicates that for line comments, the content is analyzed after the comment marker is removed [1][2]. Specifically, internal logic such as that found in BreakableComment and related classes handles the matching process by evaluating the content of the comment line against the provided regex, effectively ignoring the comment indicator itself [1][6]. It is important to note that while CommentPragmas prevents clang-format from breaking or reflowing these comments, it does not prevent the formatter from adjusting the indentation of the comment to align with the surrounding code [5]. As a result, even if a comment matches the CommentPragmas regex, it may still be moved or re-indented by clang-format if the surrounding code structure changes [5].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Read the relevant formatter setting and any in-repo pragma examples.
sed -n '50,70p' cpp/.clang-format
printf '\n--- pragma examples ---\n'
rg -n "IWYU pragma:|SPDX-" cpp -S

Repository: NVIDIA/raft

Length of output: 50368


Keep CommentPragmas anchored to the start of the comment text. Clang-format strips the comment marker before applying this regex, so removing ^ makes incidental prose containing SPDX- or IWYU pragma: act like a pragma and skip reflow.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/.clang-format` at line 59, Update the CommentPragmas regex in the
clang-format configuration to anchor both recognized pragmas at the start of the
comment text, preserving the existing IWYU pragma and SPDX matches while
preventing incidental prose from being treated as a pragma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant