I recently started experimenting with the clang-tidy
tool of llvm. Now I am trying to suppress false warnings from third party library code. For this I want to
I have found another non-invasive (without adding // NOLINT
to a third-party library) way to suppress warnings. For example, the current version of Google Test fails some cppcoreguidelines-*
checks. The following code allows you to validate the current diff excluding lines that contain gtest's macros:
git diff -U3 | sed '
s/^+\( *TEST(\)/ \1/;
s/^+\( *EXPECT_[A-Z]*(\)/ \1/;
s/^+\( *ASSERT_[A-Z]*(\)/ \1/;
' | recountdiff | interdiff -U0 /dev/null /dev/stdin | clang-tidy-diff.py -p1 -path build
It assumes that file build/compile_commands.json
is generated before and clang-tidy-diff.py
is available from your environment. recountdiff
and interdiff
from patchutils are the standard tools for manipulating patches.
The script works as follows:
git diff -U3
generates a patch with 3 context lines.sed ...
removes prefix +
from the undesired lines, i.e. transform them to the context.recountdiff
correct offsets (in first ranges) in the chunk headers.interdiff -U0 /dev/null /dev/stdin
just removes all context lines from a patch. As a result, it splits the initial hunks.clang-tidy-diff.py
reads only second ranges from chunk headers and passes them to clang-tidy
via -line-filter
option.UPD: It's important to provide interdiff
with a sufficient number of context lines, otherwise it may produce some artifacts in the result. See the citation from man interdiff
:
For best results, the diffs must have at least three lines of context.
Particularly, I have found that git diff -U0 | ... | interdiff
generates some spurious literals $!otj
after splitting chunks.