I’m using clang-tidy in my C++ project, and I’m encountering errors related to third-party dependencies, specifically Abseil (absl). I want to skip checking these dependencies.
jiawei@DESKTOP-AEQS7B5:~/Development/OSM2GMNS/OSM2GMNS$ pre-commit run
trim trailing whitespace.................................................Passed
check for added large files..............................................Passed
check yaml...........................................(no files to check)Skipped
clang-format.............................................................Passed
clang-tidy...............................................................Failed
- hook id: clang-tidy
- exit code: 1
b'as errorn'
/home/jiawei/Development/OSM2GMNS/OSM2GMNS/cmake-build-debug/_deps/absl-src/absl/container/internal/raw_hash_set.h:520:44: error: The value '0' provided to the cast expression is not in the valid range of values for 'ctrl_t' [clang-analyzer-optin.core.EnumCastOutOfRange,-warnings-as-errors]
520 | inline bool IsFull(ctrl_t c) { return c >= static_cast<ctrl_t>(0); }
Here’s my current setup:
CMakeLists.txt
cmakeCopyFetchContent_Declare(
absl
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG 20230125.3
SYSTEM
)
.pre-commit-config.yaml:
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-yaml
exclude: ".clang-*"
- repo: https://github.com/jiawlu/pre-commit-hooks
rev: 49cddc161d4fe41ee9f16922f2c0e634b0a115ff
hooks:
- id: clang-format
args: [--style=file, -i]
- id: clang-tidy
args: [-p=./cmake-build-debug, --fix-errors]
.clang-tidy
Checks: '*,-=,-fuchsia-*,-zircon-*,-modernize-use-trailing-return-type,-hicpp-use-emplace,-modernize-use-emplace,-llvm-*,-llvmlibc-*,-readability-function-cognitive-complexity,-altera-*,-openmp-exception-escape,-cppcoreguidelines-owning-memory,-bugprone-easily-swappable-parameters,-bugprone-branch-clone'
WarningsAsErrors: '*'
HeaderFilterRegex: 'src/.*'
FormatStyle: 'file'
Despite using the SYSTEM flag in FetchContent_Declare and setting HeaderFilterRegex to ‘src/.*’, clang-tidy is still checking the Abseil headers and reporting errors.
How can I configure clang-tidy to skip checking third-party dependencies like Abseil while still analyzing my own code?