[RFC][clang-tidy] Support analyzing files based on the .clang-tidy file where the identifier is declared, not where it's used

Hi,

Currently clang-tidy uses the .clang-tidy file closest to the “.cpp” file under analysis. This means it can pick up warnings from a “.h” file that is next to a totally different .clang-tidy file. This leads to confusion as to “which config is used to analyze which file”.

This is problematic also when trying to ignore warnings from 3rd-party libraries. The current solution is to use HeaderFilterRegex, to prevent warnings from e.g. 3rd-party folders, but then this filter needs to be duplicated in many places depending on the directory structure. That’s not ideal. On top of that, HeaderFilterRegex doesn’t support negative regexes (it’s a “filter-in” regex, not “filter-out”).

Would it be possible to implement this:
https://clang.llvm.org/extra/clang-tidy/checks/readability-identifier-naming.html#cmdoption-arg-getconfigperfile

for all checks? Potentially opt-in via CLI/config. In other words, have clang-tidy use the .clang-tidy file closest to where an identifier is declared (the root of the problem), not where it’s used.

Looking forward to your thoughts!

Any thoughts?

Generalizing that infrastructure in the identifier-naming-check wouldn’t be an easy undertaking, some included headers may want to disable check or enable checks that the cpp file does(or doesnt) enable. Then there is the issue that each check would need to keep track of how its configured for each file.
All these changes would definitely result in a performance nosedive