Skip to content

Conversation

shenxianpeng
Copy link
Collaborator

@shenxianpeng shenxianpeng commented Aug 30, 2025

closes #93 also

Summary by CodeRabbit

  • New Features

    • Added support for clang-format/clang-tidy v21 and expanded resolvable clang-format patch versions (latest 20.1.8).
  • Documentation

    • Updated README examples to v1.1.0, clarified migration wording/link to migration notes, and refined performance guidance for large codebases; small header edit in migration notes.
  • Tests

    • Expanded test coverage for version 21 and updated version-resolution expectations to the new latest patch.
  • Chores

    • Bumped pre-commit hook revisions and updated tooling dependency references; added/configured additional test-oriented pre-commit entries and adjusted test success threshold.

@shenxianpeng shenxianpeng added the enhancement New feature or request label Aug 30, 2025
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 30, 2025
@shenxianpeng shenxianpeng added the minor A minor version bump label Aug 30, 2025
Copy link

codecov bot commented Aug 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.48%. Comparing base (924f4de) to head (008459b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #97   +/-   ##
=======================================
  Coverage   94.48%   94.48%           
=======================================
  Files           3        3           
  Lines         145      145           
=======================================
  Hits          137      137           
  Misses          8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

coderabbitai bot commented Aug 30, 2025

Walkthrough

Adds clang-format patch/major versions (20.1.8, 21.1.0), updates optional tooling pin to 21.1.0, expands tests to cover clang-format/clang-tidy v21 and resolves 20/20.1 → 20.1.8, bumps two pre-commit hook revisions, and updates README and migration notes.

Changes

Cohort / File(s) Summary
Pre-commit configuration
\.pre-commit-config.yaml
Bumped hook revisions: pre-commit-hooks v5.0.0 → v6.0.0 and astral-sh/ruff-pre-commit v0.12.2 → v0.12.11.
Documentation & migration notes
README.md, docs/migration-notes.md
Updated README examples and snippets to v1.1.0, reworded migration phrasing and link to docs/migration-notes.md; minor header edit in migration notes. Documentation-only edits.
Clang-format versions & tooling
cpp_linter_hooks/util.py, pyproject.toml
Added clang-format versions 20.1.8 and 21.1.0 to supported list (retained 20.1.7); updated optional clang-format tooling pin to 21.1.0 in pyproject.toml.
Tests — clang-format & util
tests/test_clang_format.py, tests/test_util.py
Added test cases for clang-format v21; updated expected resolution so 20/20.1 resolve to 20.1.8 (previously 20.1.7).
Tests — clang-tidy
tests/test_clang_tidy.py
Appended clang-tidy v21 parameter cases to existing parameterized tests (expectations unchanged).
Testing pre-commit configs
testing/pre-commit-config-verbose.yaml, testing/pre-commit-config-version.yaml
Updated verbose test config to use clang-format v21; added new repo: . block at rev: HEAD including clang-format --version=21 and clang-tidy --version=20.
Test runner threshold
testing/run.sh
Adjusted expected failed test count from 9 → 10 in the success condition.

Sequence Diagram(s)

(Skipped — changes are data/tests/docs/version bumps; no control-flow or feature-level interactions to diagram.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Bump clang-format from 20.1.7 to 20.1.8 in the pip group (#93)

Out-of-scope changes

Code Change Explanation
Pre-commit hook revision bumps (.pre-commit-config.yaml) Hook rev bumps are repository maintenance and are unrelated to the pip clang-format bump requested in #93.
Addition of clang-format 21.1.0 and tooling pin update to 21.1.0 (pyproject.toml, cpp_linter_hooks/util.py) Introducing support and pin for 21.1.0 goes beyond the single-patch bump to 20.1.8 requested by #93.
README version updates and migration phrasing (README.md) Documentation/example version changes are not part of the pip dependency bump objective in #93.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/support-clang-v21

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
cpp_linter_hooks/util.py (1)

163-172: Handle version=None installs gracefully to avoid “==None”.

If defaults are None (your tests simulate this), _install_tool would attempt to pip install f"{tool}==None". Instead, install unpinned when version is None.

Apply this diff:

 def _install_tool(tool: str, version: str) -> Optional[Path]:
     """Install a tool using pip."""
     try:
-        subprocess.check_call(
-            [sys.executable, "-m", "pip", "install", f"{tool}=={version}"]
-        )
+        cmd = (
+            [sys.executable, "-m", "pip", "install", f"{tool}=={version}"]
+            if version
+            else [sys.executable, "-m", "pip", "install", tool]
+        )
+        subprocess.check_call(cmd)
         return shutil.which(tool)

Follow-up: adjust tests that assert the exact pip args when version is None.

tests/test_util.py (2)

36-39: Fix runtime-version mocking to avoid unintended installs during tests.

When version is None, DEFAULT_CLANG_FORMAT_VERSION is now 21.1.0; when version is "20", _resolve_version(...) is 20.1.8. Mock the runtime accordingly to prevent triggering _install_tool.

Apply this diff:

-            # Mock _get_runtime_version to return a matching version
-            mock_version = "20.1.7" if tool == "clang-format" else "20.1.0"
+            # Mock _get_runtime_version to return a matching version for each case
+            if tool == "clang-format":
+                mock_version = (
+                    _resolve_version(CLANG_FORMAT_VERSIONS, "20")
+                    if version == "20"
+                    else DEFAULT_CLANG_FORMAT_VERSION
+                )
+            else:
+                mock_version = DEFAULT_CLANG_TIDY_VERSION

168-173: Update exact-match expectations after removing 20.1.7.

Given CLANG_FORMAT_VERSIONS no longer contains 20.1.7, the exact-match test will fail. Either switch the exact-match to 20.1.8, or assert that 20.1.7 resolves to None to document the removal.

Apply one of the following diffs.

Option A (keep exact-match semantics):

-        ("20.1.7", "20.1.7"),  # Exact match
+        ("20.1.8", "20.1.8"),  # Exact match

Option B (document removal):

-        ("20.1.7", "20.1.7"),  # Exact match
+        ("20.1.7", None),  # Removed from supported versions
♻️ Duplicate comments (1)
tests/test_clang_tidy.py (1)

47-48: Duplicate of the valid case note above.

🧹 Nitpick comments (9)
pyproject.toml (1)

51-53: Approve bump to clang-format 21.1.0; no test updates needed. Tests stub the runtime version via _get_runtime_version, so they won’t break with the new default.
Clang-tidy remains at 20.1.0—consider bumping it to 21.x for parity with “support clang v21,” or explicitly scope this PR to clang-format only.

tests/test_clang_tidy.py (2)

25-26: Adding v21 arg coverage is fine; confirm install behavior expectation.

With CLANG_TIDY_VERSIONS capped at 20.1.0, asking for “--version=21” will fall back to DEFAULT_CLANG_TIDY_VERSION at runtime. If the intent is true v21 support, add 21.x to CLANG_TIDY_VERSIONS (and optionally pin in pyproject). If fallback is intended, consider a dedicated test asserting fallback semantics.


9-13: Nit: duplicate CMake invocation.

The two consecutive cmake -Bbuild calls are redundant.

Apply this diff:

 def generate_compilation_database():
     subprocess.run(["mkdir", "-p", "build"])
-    subprocess.run(["cmake", "-Bbuild", "testing/"])
     subprocess.run(["cmake", "-Bbuild", "testing/"])
cpp_linter_hooks/util.py (1)

105-107: Version table updated; address test fallout and consider retaining 20.1.7 for back-compat.

  • Removing 20.1.7 breaks the exact-match test in tests/test_util.py (it still expects "20.1.7" → "20.1.7"). Either:
    • Re-add "20.1.7" here for back-compat, or
    • Update the test to expect None (or switch the exact-match case to 20.1.8). I’ve proposed a test fix below.

Apply this diff if you prefer back-compat:

     "20.1.6",
+    "20.1.7",
     "20.1.8",
     "21.1.0",
tests/test_util.py (1)

352-357: If you adopt unpinned install for version=None, adjust this assertion.

After updating _install_tool to handle None, the call expectation here should match the new behavior (i.e., pip install clang-format without ==version). If you keep current behavior, ignore this note.

tests/test_clang_format.py (3)

17-18: Add clang-format v21 happy-path — LGTM. Also cover patch-level.

Looks good. To harden against resolver regressions, consider adding 21.1 and 21.1.0 cases:

         (["--style=Google", "--version=21"], (0, "")),
+        (["--style=Google", "--version=21.1"], (0, "")),
+        (["--style=Google", "--version=21.1.0"], (0, "")),

44-45: Add v21 to invalid-path matrix — LGTM. Mirror patch-level too.

For symmetry with the valid matrix and to exercise error handling across patch resolution:

         (["--style=Google", "--version=20"], 1),
         (["--style=Google", "--version=21"], 1),
+        (["--style=Google", "--version=21.1"], 1),
+        (["--style=Google", "--version=21.1.0"], 1),

8-18: Parametrize tests using CLANG_FORMAT_VERSIONS from util
Import CLANG_FORMAT_VERSIONS from cpp_linter_hooks.util and derive the sorted set of major versions in tests/test_clang_format.py (lines 8–18) instead of hardcoding the list to avoid drift when versions change.

README.md (1)

62-70: Surface v21 in examples (optional).

Since v21 is now supported, consider showcasing it in snippets to guide users:

# Custom Clang Tool Version
- id: clang-format
  args: [--style=file, --version=21]
- id: clang-tidy
  args: [--checks=.clang-tidy, --version=21]
# Verbose example
- id: clang-format
  args: [--style=file, --version=21, --verbose]

Also applies to: 178-184

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 924f4de and e2f84c9.

📒 Files selected for processing (7)
  • .pre-commit-config.yaml (2 hunks)
  • README.md (6 hunks)
  • cpp_linter_hooks/util.py (1 hunks)
  • pyproject.toml (1 hunks)
  • tests/test_clang_format.py (2 hunks)
  • tests/test_clang_tidy.py (2 hunks)
  • tests/test_util.py (1 hunks)
🔇 Additional comments (9)
.pre-commit-config.yaml (2)

3-3: Pre-commit hooks bump: LGTM.


17-17: Ruff pre-commit bump: LGTM.

README.md (7)

35-35: Bump rev to v1.1.0 — LGTM.


50-50: Keep examples consistent — LGTM.


65-65: Rev updated in Custom Clang Tool Version block — LGTM.


73-73: Migration note clarity — LGTM.

Wording correctly reflects the pre-commit hook using wheels.


151-151: Performance tip refinement — LGTM.


154-154: Rev bump maintained in performance example — LGTM.


181-181: Rev bump maintained in verbose example — LGTM.

Copy link

codspeed-hq bot commented Aug 30, 2025

CodSpeed Performance Report

Merging #97 will degrade performances by 11.12%

Comparing feature/support-clang-v21 (008459b) with main (924f4de)

Summary

❌ 2 regressions
✅ 65 untouched benchmarks
🆕 6 new benchmarks
⁉️ 2 dropped benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 test_run_clang_format_invalid[args6-1] N/A 845.8 µs N/A
🆕 test_run_clang_format_valid[args6-expected_retval6] N/A 986.6 µs N/A
🆕 test_run_clang_tidy_invalid[args6-1] N/A 850.8 µs N/A
🆕 test_run_clang_tidy_valid[args6-1] N/A 929.6 µs N/A
test_ensure_installed[clang-format-20] 1.2 ms 1.4 ms -11.12%
test_ensure_installed[clang-format-None] 1.2 ms 1.3 ms -10.45%
⁉️ test_resolve_version_clang_format[20-20.1.7] 133.1 µs N/A N/A
🆕 test_resolve_version_clang_format[20-20.1.8] N/A 137.1 µs N/A
⁉️ test_resolve_version_clang_format[20.1-20.1.7] 133.1 µs N/A N/A
🆕 test_resolve_version_clang_format[20.1-20.1.8] N/A 136.7 µs N/A

@shenxianpeng shenxianpeng changed the title feat: support clang v21 feat: support clang-format v21 Aug 30, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (8)
testing/pre-commit-config-verbose.yaml (2)

2-3: Prefer a fixed rev over HEAD in examples/tests to avoid flaky autoupdate warnings.

Pin to a tag or commit unless HEAD is intentional for the test. If intentional, add a comment to silence confusion.

Apply:

-  - repo: .
-    rev: HEAD
+  - repo: .
+    rev: v1.1.0  # Intentional: use a fixed tag to avoid mutable ref warnings

11-11: Same as above: ensure -v path is exercised.

If not covered elsewhere, add a test that runs with "-v".

testing/pre-commit-config-version.yaml (1)

2-3: Avoid mutable rev: HEAD in public examples.

Use a fixed tag to prevent pre-commit warnings and ensure reproducibility.

-  - repo: .
-    rev: HEAD
+  - repo: .
+    rev: v1.1.0

(Repeat for each block if these files are used as user-facing examples.)

README.md (5)

57-70: Update versioned example to showcase the newly supported 21.

Align the sample with the PR goal (support clang v21).

   - repo: https://github.com/cpp-linter/cpp-linter-hooks
-    rev: v1.1.0
+    rev: v1.1.0
   hooks:
     - id: clang-format
-      args: [--style=file, --version=18] # Specifies version
+      args: [--style=file, --version=21] # Specifies version
     - id: clang-tidy
-      args: [--checks=.clang-tidy, --version=18] # Specifies version
+      args: [--checks=.clang-tidy, --version=21] # Specifies version

72-74: Minor wording: clarify what --version does.

“Loads style configuration via --version” is misleading elsewhere; --version selects tool version, not style.

Consider: “To select tool version, use --version. Style/checks are loaded via --style=file and --checks=.clang-tidy.”


149-162: Keep version examples consistent with v21 across docs.

Optional but improves cohesion.

-  rev: v1.1.0
+  rev: v1.1.0
 ...
-    - id: clang-format
-      args: [--style=file, --version=20]
+    - id: clang-format
+      args: [--style=file, --version=21]
 ...
-    - id: clang-tidy
-      args: [--checks=.clang-tidy, --version=20]
+    - id: clang-tidy
+      args: [--checks=.clang-tidy, --version=21]

178-184: Verbose example: bump to 21 for consistency.

Keep examples uniform with newly added support.

-    rev: v1.1.0
+    rev: v1.1.0
 ...
-        args: [--style=file, --version=18, --verbose]   # Add -v or --verbose for detailed output
+        args: [--style=file, --version=21, --verbose]   # Add -v or --verbose for detailed output

190-197: Table row phrasing: fix “Loads style configuration via --version”.

Use accurate flags for style/checks loading.

-| Loads style configuration        | ✅ via `--version`                        | ✅ (default behavior)                  |
+| Loads style/checks configuration | ✅ via `--style=file` / `--checks=.clang-tidy` | ✅ (default behavior)              |
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8f9ab and cd08d50.

📒 Files selected for processing (3)
  • README.md (6 hunks)
  • testing/pre-commit-config-verbose.yaml (1 hunks)
  • testing/pre-commit-config-version.yaml (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
testing/pre-commit-config-verbose.yaml (1)
tests/test_clang_format.py (1)
  • test_run_clang_format_verbose (73-86)
🪛 GitHub Actions: Test
testing/pre-commit-config-verbose.yaml

[warning] 1-1: Warning: The 'rev' field of repo '.' appears to be a mutable reference; pre-commit autoupdate recommended.

testing/pre-commit-config-version.yaml

[warning] 1-1: Warning: The 'rev' field of repo '.' appears to be a mutable reference; pre-commit autoupdate recommended.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run benchmarks
🔇 Additional comments (2)
testing/pre-commit-config-verbose.yaml (1)

6-6: Cover both verbose flags in tests.

This config exercises --verbose; add/confirm a test that exercises -v as well (mirrors the second block).

Do you want me to add a parametrized test for ["--verbose", "-v"] to test_run_clang_format_verbose?

README.md (1)

31-40: Pin the example to the latest released tag.

Good update to v1.1.0. LGTM.

Comment on lines 37 to 43
- repo: .
rev: HEAD
hooks:
- id: clang-format
args: [--style=file, --version=21]
- id: clang-tidy
args: [--checks=.clang-tidy, --version=21]
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Validate clang-tidy 21 wheel availability and hook resolution.

You added --version=21 for clang-tidy, but optional deps remain at 20.1.0 in pyproject. Verify the hook downloads/uses the 21.x wheel at runtime on CI.

Run:


🏁 Script executed:

#!/bin/bash
# Check PyPI for clang-tidy 21 availability
curl -s https://pypi.org/pypi/clang-tidy/json | jq -r '.releases | keys[]' | rg '^21(\.|$)' -n
# Print latest version for visibility
curl -s https://pypi.org/pypi/clang-tidy/json | jq -r '.info.version'

Length of output: 173


Align clang-tidy hook version with available wheel

PyPI only hosts clang-tidy up to version 20.1.0 (no 21.x releases), so --version=21 will fail at hook resolution; revert the hook to --version=20.1.0 (to match your optional deps) or wait for a 21.x wheel before bumping.

🤖 Prompt for AI Agents
In testing/pre-commit-config-version.yaml around lines 37 to 43, the clang-tidy
hook is pinned to --version=21 which is not available on PyPI; update the
clang-tidy hook to use --version=20.1.0 to match the available wheel (or
remove/bump only when a 21.x wheel exists). Edit the args for the clang-tidy
entry to replace --version=21 with --version=20.1.0 so pre-commit can resolve
the hook successfully.

Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
testing/run.sh (1)

32-32: Bumped expected failures to 10 — verify stability and harden the check.

Confirm that 10 is the intended count across all CI environments; pre-commit output can vary slightly with hook versions. Also, prefer arithmetic test to avoid word-splitting/unset issues.

Apply this minimal change to the condition:

-if [ $failed_cases -eq 10 ]; then
+if (( failed_cases == 10 )); then

Optional hardening (outside this line): initialize and clean up the results file and make grep safer.

# At the top, before first run:
RESULT_FILE="$(mktemp)"; trap 'rm -f "$RESULT_FILE"' EXIT
: > "$RESULT_FILE"

# Replace result.txt usages with "$RESULT_FILE"
pre-commit run ... | tee -a "$RESULT_FILE" || true
failed_cases=$(grep -c -F "Failed" "$RESULT_FILE" || true)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4975283 and 008459b.

📒 Files selected for processing (1)
  • testing/run.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (3.14)
  • GitHub Check: Run benchmarks

@shenxianpeng shenxianpeng merged commit 8b2b307 into main Aug 30, 2025
16 of 17 checks passed
@shenxianpeng shenxianpeng deleted the feature/support-clang-v21 branch August 30, 2025 18:56
@shenxianpeng shenxianpeng removed the documentation Improvements or additions to documentation label Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor A minor version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant