[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Thu May 9 13:11:21 PDT 2024


================
@@ -311,7 +311,12 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
     : Context(Ctx), ExternalDiagEngine(ExternalDiagEngine),
       RemoveIncompatibleErrors(RemoveIncompatibleErrors),
       GetFixesFromNotes(GetFixesFromNotes),
-      EnableNolintBlocks(EnableNolintBlocks) {}
+      EnableNolintBlocks(EnableNolintBlocks) {
+
+  if (Context.getOptions().ExcludeHeaderFilterRegex)
+    ExcludeHeaderFilter = std::make_unique<llvm::Regex>(
+        *Context.getOptions().ExcludeHeaderFilterRegex);
+}
----------------
5chmidti wrote:

It's not a good idea to have basically the same thing implemented in two different ways (`HeaderFilter` vs `ExcludeHeaderFilter`). I think the `ExcludeHeaderFilter` should be implemented like the `HeaderFilter`.
https://github.com/llvm/llvm-project/blob/dcf92a249233cab103f848dd12e96e0d642a8899/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp#L574-L579
This would also solve @PiotrZSL's comment.

We can probably save the constructions of `llvm::Regex` and the call to `match` on the empty regex. wdyt? This could also be done in another pr.

https://github.com/llvm/llvm-project/pull/91400


More information about the cfe-commits mailing list