2

I use clang-tidy to lint project code. The project uses third-party headers, e.g. from cmake generated protobuf files like logger.pb.h. I only want to lint project specific source file and want to handle third-party headers as system headers, therefor i use -isystem.

My project tree looks like:

source
└── logger.cpp

dependencies
└── include
    ├── logger.pb.h
    └── queue.h

Since i use a dynamic script i have a mix by using a .clang-tidy config file and i call this

clang-tidy -export-fixes=fixes.txt /path/to/logger.cpp -- -isystem /path/to/dependencies/include

with the config-file .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 shows errors in my source file logger.cpp as expected. But it also complains about the third party headers i use and i don't know how to get rid of:

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 also tried:

-I /path/to/dependencies/include
-isystem=/path/to/dependencies/include
Chris
  • 315
  • 1
  • 4
  • 17
  • related and possible dup-target: [clang-tidy - ignore third party headers code](/q/61101056/11107541) – starball May 04 '23 at 04:37

1 Answers1

0

at the end i used -isystem /path/to/dependencies/include and it worked. I don't know why it didn't work before.

Chris
  • 315
  • 1
  • 4
  • 17
  • 2
    I'm having the same problem and `-isystem` did not solve it. It still shows errors on the system headers. Got any idea why? – Alaa M. Nov 15 '21 at 11:54
  • don't know and without knowledge about your setup it is hard to say – Chris Nov 15 '21 at 15:21
  • Here's the details: https://stackoverflow.com/questions/69972577/clang-tidy-displays-errors-in-system-headers it'd be great if you can take a look. Should I provide any more info? – Alaa M. Nov 15 '21 at 19:05