我有一个简单的c++项目与Bazel。我正在使用谷歌测试框架运行一些简单的测试。Clang-tidy似乎抱怨来自该框架的几乎每一个宏。有没有办法让clang忽略这些宏?我尝试使用//NOLINT,但它似乎没有做任何事情。
我的clang-tidy配置文件如下:
Checks: '-*,clang-analyzer-*,
modernize-avoid-bind,
modernize-avoid-c-arrays,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-unary-static-assert,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
modernize-use-using,
performance-*,readability*,cppcoreguidelines-*, llvm-*,
google-*,
bugprone-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
CheckOptions:
[{key: readability-identifier-naming.ClassCase, value: CamelCase},
{key: readability-identifier-naming.ClassMemberCase, value: lower_case},
{key: readability-identifier-naming.PrivateMemberPrefix, value: m_},
{key: readability-identifier-naming.ClassMethodCase, value: lower_case},
{key: readability-identifier-naming.StructCase, value: lower_case},
{key: readability-identifier-naming.VariableCase, value: lower_case},
{key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE},
]
我得到的警告是Initializing non-owner argument of type 'testing::internal::TestFactoryBase *' with a newly created 'gsl::owner<>'clang-tidy(cppcoreguidelines-owning-memory)
//NOLINT
需要放在代码中出现问题的地方,即您使用宏的地方。如果你把它放在很多地方,这会很麻烦。
另一个选项是排除你的测试文件clang-tidy cmake排除文件从检查或者配置2个clang-tidy运行(一个用于不检查的测试,一个用于检查的prod)。不确定是否可以在Bazel中建模,因为到目前为止我还没有使用它
最后一个选项:在GitHub https://github.com/google/googletest/issues中打开一个问题或在googletest源代码中自己修复它并打开拉取请求。