Skip to content

Add cppcheck static analysis to car/ CI#98

Closed
ltowarek wants to merge 1 commit into
cpp_linters_clang_tidyfrom
cpp_linters_cppcheck
Closed

Add cppcheck static analysis to car/ CI#98
ltowarek wants to merge 1 commit into
cpp_linters_clang_tidyfrom
cpp_linters_cppcheck

Conversation

@ltowarek

Copy link
Copy Markdown
Owner

Summary

  • Adds car/.cppcheck-suppressions and car/scripts/run_cppcheck.sh, run via a new blocking cppcheck CI job (added to ci-status-cpp-car's needs) and wired into car/scripts/run_checks.sh/pre-commit.sh.
  • Runs against compile_commands.json from a regular idf.py build — the production GCC toolchain, no special toolchain detour needed (unlike clang-tidy).
  • Suppresses findings transitively reported on vendored dependencies and the ESP-IDF SDK itself (*:*/esp-opentelemetry-cpp/*, *:/opt/esp/idf/*) — not actionable from owned code.
  • Adds inline // cppcheck-suppress syntaxError comments (4 call sites) for a confirmed cppcheck parser limitation with ESP-IDF's variadic ESP_LOGx macros — verified these are false positives, not real syntax errors (the real GCC build already catches genuine syntax errors).
  • Fixes the only two real findings: cJSON_GetObjectItem(...) results in command_parser.cpp can be const cJSON * (cJSON's own API already takes const cJSON *, so this is a no-op at the ABI level).

Part of #87.

Test plan

  • ./scripts/run_cppcheck.sh passes cleanly (exit 0) from a clean build
  • Production GCC build succeeds after the const-correctness fix

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

https://claude.ai/code/session_01QwTBvENKGMczMo9x7nAMrg

@ltowarek
ltowarek force-pushed the cpp_linters_cppcheck branch from bd552c8 to a6c2da6 Compare June 21, 2026 21:16
@ltowarek
ltowarek changed the base branch from main to cpp_linters_clang_tidy June 21, 2026 21:17
@ltowarek
ltowarek force-pushed the cpp_linters_cppcheck branch from a6c2da6 to bab0dd0 Compare June 21, 2026 21:22
Runs cppcheck against the production compile_commands.json (no
special toolchain needed). Suppresses findings transitively reported
on vendored/SDK headers and a handful of confirmed cppcheck parser
false positives on ESP-IDF's variadic ESP_LOGx macros, with reasoning
inline. Fixes two real const-correctness findings in
command_parser.cpp. Part of #87.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QwTBvENKGMczMo9x7nAMrg
@ltowarek

Copy link
Copy Markdown
Owner Author

Closing without merging. While investigating a complaint that the cppcheck-suppress comment above the first ESP_LOGx call per file felt unacceptable, it turned out cppcheck is barely analyzing this codebase at all (4/592 checkers active project-wide) — it aborts each translation unit on its first critical parse error, and nearly every file hits one (either the ESP_LOGx VA_OPT macro or a vendored OTel #error directive). The CI job was passing regardless of actual code quality.

#99 has been rebased to sit directly on #97, skipping this branch. Filed #100 with the full diagnosis to revisit cppcheck properly later.

@ltowarek ltowarek closed this Jun 21, 2026
@ltowarek ltowarek mentioned this pull request Jun 21, 2026
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.

1 participant