'Is it possible to ignore a header with clang-tidy
I want to include a header from an external project, but clang-tidy is quite unhappy about it and produces a huge list of warnings. To workaround this, I am trying to disable all diagnostics coming from this header.
I tried:
// NOLINTBEGIN
// NOLINTNEXTLINE
#include <bad.hpp> // NOLINT
// NOLINTEND
But this does not work unfortunately.
This email thread suggests to use -header-filter (HeaderFilterRegex) option.
HeaderFilterRegex: '^((?!bad.hpp).)*$'
But this results into all headers being ignored, since clang tidy uses POSIX regex syntax. Which does not support negative look ahead.
I also considered using line-filter for this as this answer suggests, but there is no such option for the config file.
Is it possible at all?
Solution 1:[1]
As of today (Apr 19 2022), this thread on disclosure llvm blog suggests that the feature is not supported.
Relevant notes are:
HeaderFilterRegexis parsed usingllvm::Regex, which does not support negative lookahead.- Using
std::regexinstead ofllvm::Regexis not possible yet, as some compilers do not havestd::regexsupport. Future versions ofclang-tidymay implement glob based file names filtering.
I can see only two possible workarounds for this now:
- List all the allowed paths in
HeaderFilterRegex. - Patch
clang-tidyto usestd::regexand use your own version.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ivaigult |
