问题
I have projects that sets Clang-tidy configuration as following
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=google-*,cppcoreguidelines-*;")
However, I have noticed that it was checking all the files that are not even in the current repo like
/opt/ros/melodic/include/ros/console.h
and all the .h/.hpp files of submodules...
I tried to add a regex to filter the target .h files but couldn't get it working...
I have given absolute path for a single .hpp file but it was still evaluating /opt/ros/melodic/include
files...
Can I have an example on header-filter??
I assume clang-tidy will check the corresponding cpp file if hpp is in the filter. am I correct?
回答1:
You can look at this example. That's my commit. https://github.com/cocos2d/cocos2d-x/pull/19928
This is how I disabled clang-tidy checks on two directories with regular expressions.
'^((?!/cocos2d-x/external/|/cocos/scripting/).)*$'
It disables clang-tidy checks on external
directory and cocos/scripting
directory.
I create a python script to test whether the regular expression is working as intended.
#!/usr/bin/env python
import re
files = [
"/home/john/cocos2d-x/external/openssl/include/linux/openssl/bio.h",
"/home/john/cocos2d-x/external/tiff/include/linux/tiff.h",
"/home/john/git/cocos/cocos2d-x/cocos/scripting/lua-bindings/auto/lua_cocos2dx_3d_auto.cpp"
"/home/john/cocos2d-x/external/json/stringbuffer.h",
"/home/john/cocos2d-x/cocos/base/ccUtils.h",
"/home/john/git/cocos/cocos2d-x/cocos/scripting/js-bindings/precheader.cpp",
"/home/john/cocos2d-x/cocos/physics/CCPhysicsBody.cpp",
"/home/john/cocos2d-x/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp",
"/home/john/cocos2d-x/templates/cpp-template-default/Classes/AppDelegate.cpp",
"/home/john/git/cocos/cocos2d-x/cocos/scripting/js-bindings/proj.android/CMakeLists.txt",
]
pattern = '^((?!/cocos2d-x/external/|/cocos/scripting/).)*$'
for file in files:
m = re.search(pattern, file)
if m:
print m.group(0)
Running this python file and the output is
/home/john/cocos2d-x/cocos/base/ccUtils.h
/home/john/cocos2d-x/cocos/physics/CCPhysicsBody.cpp
/home/john/cocos2d-x/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp
/home/john/cocos2d-x/templates/cpp-template-default/Classes/AppDelegate.cpp
You can modify the regular expression and python test script to see if it works.
来源:https://stackoverflow.com/questions/61001314/what-is-the-correct-way-of-providing-header-filter-for-clang-tidy-in-cmake