10

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?

ivaigult
  • 6,198
  • 5
  • 38
  • 66
  • 1
    "Is it possible at all" is a broad question ;-) But you will most likely have some limitations. Do you use run-clang-tidy (with a compile-commands DB) or clang-tidy? Would patching clang-tidy an option? – Sonic78 Apr 14 '22 at 15:07
  • Yeah, judging by [this thread](https://discourse.llvm.org/t/clang-tidy-negative-lookahead-support/39007), I can replace `llvm::Regex` with `std::regex`, which should allow negative lookahead. – ivaigult Apr 19 '22 at 09:38
  • I suspect, the answer to my question is a "no". Vanilla `clang-tidy` does not support this yet. – ivaigult Apr 19 '22 at 09:39

1 Answers1

7

As of today (Apr 19 2022), this thread on disclosure llvm blog suggests that the feature is not supported.

Relevant notes are:

  • HeaderFilterRegex is parsed using llvm::Regex, which does not support negative lookahead.
  • Using std::regex instead of llvm::Regex is not possible yet, as some compilers do not have std::regex support. Future versions of clang-tidy may 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-tidy to use std::regex and use your own version.
ivaigult
  • 6,198
  • 5
  • 38
  • 66
  • I tried using '^.*\.hpp$' which I believe should match all hpp files. (I tried lots of other combinations including '.*' too. However, I see that in the "problems" window in VSCode I still see lots of .h files and .hpp files too. Do you have any suggestions? – GMoney May 27 '22 at 10:05
  • @GMoney this might be a separate VSCode problem. run-clang-tidy understands such regex. – ivaigult Jun 10 '22 at 14:29