ci(clang-tidy): stop false positives in the inline review comments (#29013)

* ci(clang-tidy): stop false positives in the inline review comments

Of the 828 inline comments the clang-tidy job posted on 98 PRs since May, only 328 were unique: COMMENT reviews can't be dismissed, so every push posted every finding again. Most of the rest were artifacts of how the diff step runs:

- It parses against the test build dir, which is only configured, so the uORB, events and parameter headers don't exist and every TU stops at a missing include. clang-tidy then reports on the half-parsed AST: events::send<T>(...) as a chained comparison, sizeof on uORB arrays as sizeof of a pointer.
- It parses every changed .h on its own as C++, including board configs, NuttX headers and headers shared with C. The gating run never lints .h.
- .clang-tidy disabled macro-parentheses, incorrect-roundings and misplaced-widening-cast under their old misc- names, which clang-tidy 18 no longer knows, so all three were on.

Generate the test dir's headers, skip .h and board/NuttX files, drop clang-diagnostic-error (the build jobs report real compile errors), skip findings already posted on the PR, and disable four checks that only produced noise: googletest underscore names, virtual-class-destructor on gtest fixtures and singletons, suspicious-call-argument, and not-null-terminated-result on binary packet buffers.

Assisted-by: Claude:claude-opus-5-5

* ci(clang-tidy): keep the gating checks and skip the fuzztest header

.clang-tidy also configures the gating run, which enabled incorrect-roundings, macro-parentheses and virtual-class-destructor on purpose, with code fixes. Drop the stale misc- names instead of renaming them, and turn virtual-class-destructor, suspicious-call-argument and not-null-terminated-result off for the inline comments only.

Header generation also built fuzztest's json_grammar.h, which pulls in abseil and the antlr4 runtime: 336 ninja edges and 39 s in CI instead of 22 edges and 4 s.

Match already-posted comments on the line too, so a second finding with the same message elsewhere in a file is still posted. Drop only headers under boards/ and platforms/nuttx/, so SITL's own board sources are still linted.

Assisted-by: Claude:claude-opus-5-5
This commit is contained in:
Jacob Dahl authored and GitHub committed 2026-10-06 19:52:54 -06:00
1 parent dfa1d03ea1
commit a4697ed08e
4 files changed
+70 -27

No files matched your search

+1 -3
View File
@@ -72,9 +72,6 @@ Checks: '*,
-llvm-header-guard,
-llvm-include-order,
-llvm-namespace-comment,
-misc-incorrect-roundings,
-misc-macro-parentheses,
-misc-misplaced-widening-cast,
-misc-redundant-expression,
-misc-unconventional-assign-operator,
-misc-unused-parameters,
@@ -177,6 +174,7 @@ Checks: '*,
-misc-definitions-in-headers,
-bugprone-casting-through-void,
-readability-redundant-string-init,
-google-readability-avoid-underscore-in-googletest-name,
'
WarningsAsErrors: '*'
CheckOptions:
+19 -1
View File
@@ -95,7 +95,7 @@ jobs:
# Two clang build directories, prepared one after the other so their
# configures never fetch submodules at the same time:
# - build/px4_sitl_default-clang-test: configure-only, BUILD_TESTING=ON
# - build/px4_sitl_default-clang-test: configure + generated headers only, BUILD_TESTING=ON
# (used by clang-tidy-diff-18.py so test files are in the
# compilation database with resolved gtest/fuzztest includes)
# - build/px4_sitl_default-clang: full build, BUILD_TESTING=OFF
@@ -104,6 +104,20 @@ jobs:
- name: Configure clang SITL with tests
run: make px4_sitl_default-clang-test
# The test build dir is never built, so generate its headers (uORB
# topics, events, parameters, mavlink, ...). Without them every TU
# stops at a missing include and clang-tidy-diff reports on the
# half-parsed AST, e.g. events::send<T>(...) as a chained comparison.
# fuzztest's json_grammar.h is skipped: generating it builds abseil
# and the antlr4 runtime, and no PX4 code includes it.
- name: Generate headers for clang SITL with tests
working-directory: build/px4_sitl_default-clang-test
shell: bash
run: |
ninja -t targets all \
| awk -F': ' '$2 == "CUSTOM_COMMAND" && $1 ~ /\.(h|hpp)$/ && $1 !~ /^(\/|test\/fuzztest\/)/ {print $1}' \
| xargs -r ninja
- name: Build clang SITL
run: make -j$(nproc) px4_sitl_default-clang
@@ -126,9 +140,13 @@ jobs:
--build-dir build/px4_sitl_default-clang-test \
--base-ref origin/${{ github.base_ref }} \
--out pr-review/diff.patch
# The -checks list turns checks off for these comments only; the
# gating run above keeps them. Here they also lint test code, where
# they flag gtest fixtures and binary packet buffers.
if [ -s pr-review/diff.patch ]; then
clang-tidy-diff-18.py -p1 \
-path build/px4_sitl_default-clang-test \
-checks=-cppcoreguidelines-virtual-class-destructor,-readability-suspicious-call-argument,-bugprone-not-null-terminated-result \
-export-fixes pr-review/fixes.yml \
-j0 < pr-review/diff.patch || true
else
+12 -5
View File
@@ -11,9 +11,15 @@ actually analyze against the current compilation database:
compiled. Feeding them to clang-tidy-diff produces spurious
"header not found" errors (gtest/gtest.h in particular).
- Header files (.h, .hpp, .hxx) always pass through. clang-tidy
analyzes header changes via the TUs that include them; there is
no separate TU for a header to match against the database.
- C++ headers (.hpp, .hxx) pass through. clang-tidy-diff parses each
one on its own, with flags borrowed from a nearby source file.
Those under boards/ or platforms/nuttx/ are dropped: they are not
built for SITL, so the borrowed flags are not theirs.
- .h headers are dropped. Many are shared with C or are board/NuttX
configuration, and parsed alone as C++ they draw findings that do
not apply. The gating clang-tidy run's header filter only matches
.hpp, so it never lints them either.
- All other files (CMakeLists.txt, .yml, .md, etc.) are dropped.
@@ -32,7 +38,8 @@ import sys
SOURCE_EXTS = {'.c', '.cpp', '.cc', '.cxx', '.m', '.mm'}
HEADER_EXTS = {'.h', '.hpp', '.hxx'}
HEADER_EXTS = {'.hpp', '.hxx'}
EXCLUDED_HEADER_DIRS = ('boards/', 'platforms/nuttx/')
def load_db_files(build_dir):
@@ -65,7 +72,7 @@ def keep_file(path, db_files):
"""Decide whether to keep this path in the filtered diff."""
ext = os.path.splitext(path)[1].lower()
if ext in HEADER_EXTS:
return True
return not path.startswith(EXCLUDED_HEADER_DIRS)
if ext in SOURCE_EXTS:
return path in db_files
return False
+38 -18
View File
@@ -87,6 +87,10 @@ import _github_helpers
from _github_helpers import fail as _fail
# Author of the comments the PR Review Poster posts with GITHUB_TOKEN.
BOT_LOGIN = 'github-actions[bot]'
# Markers used inside the per-comment body to call out severity. Plain
# strings rather than emojis to keep the file emoji-free per project
# preferences; the rendered Markdown is unaffected.
@@ -98,22 +102,16 @@ SINGLE_COMMENT_MARKERS = {
}
# Diagnostics we never surface as PR review comments. `file not found` from
# clang-diagnostic-error fires whenever clang-tidy analyzes a header whose
# including TU is not in the active compile_commands.json (e.g. board-
# specific NuttX headers against the SITL clang build). It is noise here,
# not a signal: the build_all_targets CI matrix compiles those headers for
# real and will fail loudly if an include is actually missing.
DROPPED_DIAGNOSTIC_PATTERNS = (
('clang-diagnostic-error', 'file not found'),
)
# Diagnostics we never surface as PR review comments. clang-diagnostic-error
# is a compile error, and here it almost always comes from parsing a header
# on its own or a file whose real flags differ from the SITL clang build's
# (missing includes, NuttX-only types, an #error for another platform). The
# build jobs compile every file for real and fail loudly on a genuine error.
DROPPED_DIAGNOSTICS = ('clang-diagnostic-error',)
def is_dropped_diagnostic(diag_name, diag_message):
for name, needle in DROPPED_DIAGNOSTIC_PATTERNS:
if diag_name == name and needle in (diag_message or ''):
return True
return False
def is_dropped_diagnostic(diag_name):
return diag_name in DROPPED_DIAGNOSTICS
# ---------------------------------------------------------------------------
@@ -156,6 +154,23 @@ def fetch_pull_request_files(client, repo, pr_number):
yield entry
def fetch_posted_comment_keys(client, repo, pr_number):
"""Return the (path, line, body) of every review comment the bot
already posted on the PR.
COMMENT reviews cannot be dismissed, so without this every push posts
the same findings again. GitHub moves `line` to the current head and
sets it to null once the comment is outdated, so a finding that only
moved still matches, and one whose comment went outdated posts again.
"""
path = 'repos/{}/pulls/{}/comments'.format(repo, pr_number)
return {
(c.get('path'), c.get('line'), c.get('body'))
for c in client.paginated(path)
if (c.get('user') or {}).get('login') == BOT_LOGIN
}
# ---------------------------------------------------------------------------
# Diagnostic ordering (adapted from platisd)
# ---------------------------------------------------------------------------
@@ -304,7 +319,7 @@ def generate_review_comments(clang_tidy_fixes, repository_root,
diag_name = diag.get('DiagnosticName', '<unknown>')
diag_message_msg = diag_message.get('Message', '')
if is_dropped_diagnostic(diag_name, diag_message_msg):
if is_dropped_diagnostic(diag_name):
dropped += 1
continue
level = diag.get('Level', 'Warning')
@@ -451,9 +466,8 @@ def generate_review_comments(clang_tidy_fixes, repository_root,
'changed in this PR')
if dropped:
print('Dropped {} diagnostic(s) matching the ignored-patterns list '
'(e.g. clang-diagnostic-error "file not found"); '
'build_all_targets covers real missing includes.'.format(dropped))
print('Dropped {} clang-diagnostic-error diagnostic(s); the build '
'jobs report real compile errors.'.format(dropped))
# ---------------------------------------------------------------------------
@@ -541,6 +555,12 @@ def main(argv=None):
print('Generated {} review comment(s)'.format(len(comments)))
if comments:
posted = fetch_posted_comment_keys(client, args.repo, args.pr_number)
comments = [c for c in comments
if (c['path'], c['line'], c['body']) not in posted]
print('{} not already posted on the PR'.format(len(comments)))
manifest = {
'pr_number': args.pr_number,
'marker': args.marker,