【发布时间】:2021-06-19 21:46:44
【问题描述】:
我使用clang-tidy 来检查项目代码。该项目使用第三方标头,例如从 cmake 生成的 protobuf 文件,如logger.pb.h。我只想对项目特定的源文件进行 lint,并希望将第三方头文件作为系统头文件处理,因此我使用-isystem。
我的项目树如下所示:
source
└── logger.cpp
dependencies
└── include
├── logger.pb.h
└── queue.h
由于我使用动态脚本,因此我使用.clang-tidy 配置文件进行混合,我称之为
clang-tidy -export-fixes=fixes.txt /path/to/logger.cpp -- -isystem /path/to/dependencies/include
使用配置文件.clang-tidy:
Checks: '-*,clang-diagnostic-*,clang-analyzer-*,readability-identifier-naming'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
- { key: readability-identifier-naming.AbstractClassCase, value: CamelCase }
- { key: readability-identifier-naming.AbstractClassPrefix, value: Abstrac }
... more keys ...
clang-tidy 按预期在我的源文件logger.cpp 中显示错误。但它也抱怨我使用的第三方标头,我不知道如何摆脱:
path/to/dependencies/include/logger.pb.h:263:57: warning: invalid case style for private member '_cached_size_' [readability-identifier-naming]
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
^~~~~~~~~~~~~
_cachedSize
path/to/source/logger.cpp:26:11: warning: invalid case style for local pointer 'MyVar' [readability-identifier-naming]
char *MyVar;
^~~~~
myVar
Suppressed 24721 warnings (24717 in non-user code, 4 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
PS:
我也试过了:
-I /path/to/dependencies/include
-isystem=/path/to/dependencies/include
【问题讨论】:
标签: c++ clang clang-tidy