-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang-tidy] HeaderFilterRegex in .clang-tidy is not applied consistently and depends on working directory #118009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As pointed out in #121969, this seems to have been introduced with #91400. From what I can tell, the problem might be due to how the initialization of
Previously, Again, this is based on a quick look, and I'm not very familiar with the codebase so I don't know if this analysis holds water at all. (For example: is |
I'm also having this problem. It seems that |
I might be facing this issue also. I've got a reproducible repo Wheest/clang-tidy-issue, where we don't want to run clang-tidy on any files under And yet with my config., I still get
Version: clang-tidy --version |
@Wheest static_asserts are compilation errors will always be shown regardless of HeaderFilterRegex. Here's a minimal repro for this issue: q/x.cpp
q/.clang-tidy
q/x.h
run: EXPECTED: warning is shown ACTUAL: warning is suppressed because Note that before #91400, or if #91400 is reverted, we get the expected behavior. This caused us to accidentally stop linting all header files after upgrading clang-tidy and seems like a rather serious issue! |
Strange, we are running latest trunk and do not observe this issue... Edit: that's probably because we have the .clang-tidy file at the root instead of a subfolder. |
@carlosgalvezp I do have a reproducible example on 316bb89 at #133453 (comment). |
Yes, I can repro on our side as well. |
Actually it doesn't even work having all files at the root. |
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
I believe the linked PR should fix all the related issues, but it'd be great if you guys can test it! |
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
Pardon my ignorance but is there a way to get a pre-built clang-tidy from a PR? Otherwise I can build and test - reading the code it does look like it would solve it |
Unfortunately not, one needs to apply the diff and build from source. |
PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009, llvm#121969, llvm#133453
…lvm#133582) PR llvm#91400 broke the usage of HeaderFilterRegex via config file, because it is now created at a different point in the execution and leads to a different value. The result of that is that using HeaderFilterRegex only in the config file does NOT work, in other words clang-tidy stops triggering warnings on header files, thereby losing a lot of coverage. This patch reverts the logic so that the header filter is created upon calling the getHeaderFilter() function. Additionally, this patch adds 2 unit tests to prevent regressions in the future: - One of them, "simple", tests the most basic use case with a single top-level .clang-tidy file. - The second one, "inheritance", demonstrates that the subfolder only gets warnings from headers within it, and not from parent headers. Fixes llvm#118009 Fixes llvm#121969 Fixes llvm#133453 Co-authored-by: Carlos Gálvez <[email protected]> (cherry picked from commit 6333fa5)
I've encountered a strange behavior regarding "HeaderFilterRegex" (other options might be affected as well...).
I've tested this with clang-tidy version 19.1.2.
With older versions (e.g. clang-tidy 18.1.2) HeaderFilterRegex works as expected, so this seems to be a new issue.
Given the following setup in a project:
. └── src ├── .clang-tidy ├── external.h ├── internal.h └── main.cpp
With the following file contents:
The expectation is that when clang-tidy is run on "main.cpp", it will report the diagnostics for "internal.h" but not for "external.h".
But this does not work consistently. It seems relevant in which workding directory clang-tidy is invoked.
No diagnostic is applied, i.e. the "HeaderFilterRegex" is essentially set to ''.
If I run clang-tidy in "src", then this works as expected (internal.h is reported, external.h is not):
Notably, if I dump the configuration with "--dump-config" the resulting configuration is identical in both cases and it clearly sets "HeaderFilterRegex" to ".*internal.*".
The text was updated successfully, but these errors were encountered: