fix: parse clang-tidy output when `WarningsAsErrors` is asserted by 2bndy5 · Pull Request #162 · cpp-linter/cpp-linter · GitHub
Skip to content

fix: parse clang-tidy output when WarningsAsErrors is asserted#162

Merged
2bndy5 merged 1 commit into
mainfrom
parse-WarningsAsErrors
Sep 28, 2025
Merged

fix: parse clang-tidy output when WarningsAsErrors is asserted#162
2bndy5 merged 1 commit into
mainfrom
parse-WarningsAsErrors

Conversation

@2bndy5

@2bndy5 2bndy5 commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

ref cpp-linter/cpp-linter-action#347

Basically, we just needed to account for the ,-warnings-as-errors appended to the rule name in square brackets.

Without WarningsAsErrors

tests/demo/demo.cpp:2:1: error: included header demo.hpp is not used directly [misc-include-cleaner]

With WarningsAsErrors

tests/demo/demo.cpp:2:1: error: included header demo.hpp is not used directly [misc-include-cleaner,-warnings-as-errors]

Summary by CodeRabbit

  • Bug Fixes
    • Improved clang-tidy note parsing to recognize a wider range of note formats, reducing missed diagnostics.
  • Chores
    • Enforced LF line endings for lock files and Git metadata via .gitattributes to ensure consistent text normalization across platforms.
  • Tests
    • Enabled all Clang-Tidy warnings as errors in the demo configuration to tighten quality gates.
    • Added a type-check suppression in a test to stabilize typing without changing runtime behavior.

ref cpp-linter/cpp-linter-action#347

Basically, we just needed to account for the `,-warnings-as-errors` appended to the rule name in square brackets.

### Without `WarningsAsErrors`
```text
tests/demo/demo.cpp:2:1: error: included header demo.hpp is not used directly [misc-include-cleaner]
```
### With `WarningsAsErrors`
```text
tests/demo/demo.cpp:2:1: error: included header demo.hpp is not used directly [misc-include-cleaner,-warnings-as-errors]
```
@2bndy5 2bndy5 added the bug Something isn't working label Sep 28, 2025
@coderabbitai

coderabbitai Bot commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/capture_tools_output/test_tools_output.py (1)

458-458: Prefer precise typing over a blanket type ignore

If the mypy complaint is about diff’s type, consider casting to the expected pygit2 type instead of ignoring the arg type altogether.

Apply this minimal change if it satisfies the checker:

-        repo.apply(diff, pygit2.GIT_APPLY_LOCATION_BOTH)  # type: ignore[arg-type]
+        repo.apply(cast(pygit2.Diff, diff), pygit2.GIT_APPLY_LOCATION_BOTH)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3fca4e1 and e7b4abf.

📒 Files selected for processing (4)
  • .gitattributes (1 hunks)
  • cpp_linter/clang_tools/clang_tidy.py (1 hunks)
  • tests/capture_tools_output/test_tools_output.py (1 hunks)
  • tests/demo/.clang-tidy (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). (21)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test (ubuntu-latest, 19)
  • GitHub Check: test (ubuntu-latest, 17)
  • GitHub Check: test (ubuntu-latest, 15)
  • GitHub Check: test (ubuntu-latest, 9)
  • GitHub Check: test (ubuntu-latest, 12)
  • GitHub Check: test (ubuntu-latest, 16)
  • GitHub Check: test (ubuntu-latest, 18)
  • GitHub Check: test (ubuntu-latest, 11)
  • GitHub Check: test (ubuntu-latest, 14)
  • GitHub Check: test (ubuntu-latest, 10)
  • GitHub Check: test (ubuntu-latest, 13)
  • GitHub Check: test (windows-latest, 10)
  • GitHub Check: test (ubuntu-latest, 20)
  • GitHub Check: test (ubuntu-latest, 21)
  • GitHub Check: test (windows-latest, 14)
  • GitHub Check: test (windows-latest, 15)
  • GitHub Check: test (windows-latest, 13)
  • GitHub Check: test (windows-latest, 18)
  • GitHub Check: test (windows-latest, 17)
  • GitHub Check: test (windows-latest, 19)
🔇 Additional comments (3)
tests/demo/.clang-tidy (1)

3-3: Demo config: enabling WarningsAsErrors is appropriate for exercising the parser

This will force clang-tidy to emit [<check>,-warnings-as-errors], which is exactly what the updated parser targets. Looks good.

.gitattributes (1)

14-16: Normalize additional text files to LF — good hardening

Lock files and Git metadata benefit from consistent EOLs across platforms. Change is safe and reduces flaky diffs.

cpp_linter/clang_tools/clang_tidy.py (1)

13-15: Adopt the non-greedy named-group regex Verified against sample lines—including Windows paths and -warnings-as-errors suffix—ensuring correct captures.

Comment thread tests/demo/.clang-tidy
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,performance-*,bugprone-*,clang-analyzer-*,mpi-*,misc-*,readability-*'
WarningsAsErrors: ''
WarningsAsErrors: '*'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Previously, this would cause a test failure (tests/capture_tools_output/test_database_path.py::test_ninja_database).
Now all is well with the change in RegEx pattern.

@codecov

codecov Bot commented Sep 28, 2025

Copy link
Copy Markdown

@2bndy5 2bndy5 merged commit 4d51599 into main Sep 28, 2025
43 checks passed
@2bndy5 2bndy5 deleted the parse-WarningsAsErrors branch September 28, 2025 13:36
2bndy5 added a commit to cpp-linter/cpp-linter-rs that referenced this pull request Oct 2, 2025
2bndy5 added a commit to cpp-linter/cpp-linter-rs that referenced this pull request Oct 2, 2025
2bndy5 added a commit to cpp-linter/cpp-linter-rs that referenced this pull request Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant