5

I'm using clang-tidy in a medium-size project with the following three folders:

srcA
srcB
external

I'm trying to exclude external folder from the analysis, but with no luck. The command I'm using is:

clang-tidy $SRC -p build/ --extra-arg=-ferror-limit=0'

with

SRC=srcA/file.cpp srcA/fileN.cpp srcB/file.cpp srcB/fileN.cpp ...

and a compilation database under build/ generated by cmake. Note that SRC doesn't contain any external file, only from srcA and srcB (both .cpp and .hpp). Also, and obviusly, some files under srcA and srcB are using libraries under external.

The 80% of the errors from clang-tidy comes from external/ files, which I can't fix because there're third party libraries.

Below, the .clang-tidy file I'm using:

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'

I know this question is already posted here, but I've tried the proposed solutions and none of them worked. For example, I've tried using HeaderFilterRegex, matching only the desired files, and didn't work.

Am I missing something? Is this even possible to achieve (I've read in some page that this is a known bug from clang-tidy)?

tsarquis88
  • 453
  • 1
  • 6
  • 14

2 Answers2

3

I found the following workaround.

Project structure:

- project/.clang-tidy
- project/srcA/
- project/srcB/
- project/external/
- project/external/.clang-tidy

Top-level project/.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: ''

Then create a separate .clang-tidy file in the folder you want to ignore/exclude, with the following contents.

project/external/.clang-tidy:

# File: project/external/.clang-tidy

# Disable all checks in this folder.
Checks: '-*'

I then run clang-tidy with the command:

$ fd '\.(c|h)$' -X clang-tidy {} -p build/ --quiet
miguno
  • 14,498
  • 3
  • 47
  • 63
1

I am afraid it's impossible at the moment. It seems the only possible solution: list all the allowed paths except external/ in HeaderFilterRegex in .clang-tidy.

See the discussion thread "clang-tidy Negative Lookahead Support".

273K
  • 29,503
  • 10
  • 41
  • 64