clang-tidy:从分析中排除特定目录

tsa*_*s88 7 c++ cmake linter clang-tidy

clang-tidy我正在一个具有以下三个文件夹的中型项目中使用:

srcA
srcB
external
Run Code Online (Sandbox Code Playgroud)

我试图external从分析中排除文件夹,但没有成功。我正在使用的命令是:

clang-tidy $SRC -p build/ --extra-arg=-ferror-limit=0'
Run Code Online (Sandbox Code Playgroud)

SRC=srcA/file.cpp srcA/fileN.cpp srcB/file.cpp srcB/fileN.cpp ...
Run Code Online (Sandbox Code Playgroud)

build/以及由生成的编译数据库cmake。请注意,SRC 不包含任何external文件,仅包含srcAsrcB(.cpp 和 .hpp)。此外,显然,srcAsrcB下的一些文件正在使用external.

80% 的错误来自clang-tidy文件external/,我无法修复这些错误,因为有第三方库。

下面是.clang-tidy我正在使用的文件:

Checks: '-*,readability-identifier-naming'
WarningsAsErrors: "*"
CheckOptions:
  - { key: readability-identifier-naming.ClassCase, value: CamelCase }
  - { key: readability-identifier-naming.ClassMethodCase, value: camelBack }
  - { key: readability-identifier-naming.VariableCase, value: camelBack }
  - { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
  - { key: readability-identifier-naming.PrivateMemberCase, value: camelBack }
  - { key: readability-identifier-naming.FunctionCase, value: camelBack }
  - { key: readability-identifier-naming.MethodCase, value: camelBack }
  - { key: readability-identifier-naming.ParameterCase, value: camelBack }
  - { key: readability-identifier-naming.MemberCase, value: camelBack }
  - { key: readability-identifier-naming.EnumCase, value: CamelCase }
  - { key: readability-identifier-naming.StructCase, value: CamelCase }
  - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
  - { key: readability-identifier-naming.TypeAliasCase, value: CamelCase }
  - { key: readability-identifier-naming.TypedefCase, value: CamelCase }
  - { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE }
  - { key: readability-identifier-naming.ConstantCase, value: UPPER_CASE }
FormatStyle: 'file'
Run Code Online (Sandbox Code Playgroud)

我知道这个问题已经发布在这里,但我已经尝试了建议的解决方案,但没有一个有效。例如,我尝试使用HeaderFilterRegex,仅匹配所需的文件,但没有成功。

我错过了什么吗?这是否有可能实现(我在某些页面上读到这是一个已知的错误clang-tidy)?

Mic*_*oll 5

我找到了以下解决方法。

项目结构:

- project/.clang-tidy
- project/srcA/
- project/srcB/
- project/external/
- project/external/.clang-tidy
Run Code Online (Sandbox Code Playgroud)

顶层project/.clang-tidy

- project/.clang-tidy
- project/srcA/
- project/srcB/
- project/external/
- project/external/.clang-tidy
Run Code Online (Sandbox Code Playgroud)

.clang-tidy然后在要忽略/排除的文件夹中创建一个单独的文件,其中包含以下内容。

project/external/.clang-tidy

# File: project/.clang-tidy

Checks: '-*,readability-identifier-naming'
WarningsAsErrors: "*"
#
# ...more configs here...
#

# IMPORTANT: Set HeaderFilterRegex as shown below.
# Do not set it to '.*', for example.
HeaderFilterRegex: ''
Run Code Online (Sandbox Code Playgroud)

然后我使用以下命令运行 clang-tidy:

$ fd '\.(c|h)$' -X clang-tidy {} -p build/ --quiet
Run Code Online (Sandbox Code Playgroud)


S.M*_*.M. 1

目前恐怕是不可能的。external/这似乎是唯一可能的解决方案:列出除in之外HeaderFilterRegex的所有允许的路径.clang-tidy

请参阅讨论主题“clang-tidy Negative Lookahead Support”