Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore certain files when using clang-tidy

I'm trying to integrate clang-tidy with cmake, but there are some files that belong to a particular target which I would like to ignore.

Is there any way to make clang-tidy to ignore files under certain directory or whose name matches a certain pattern?

like image 516
Dan Avatar asked Jan 29 '26 09:01

Dan


2 Answers

CMake 3.27

3.27 introduces the SKIP_LINTING file property to handle this nicely.

add_executable(MyApp main.cpp things.cpp generatedBindings.cpp)

set_source_files_properties(generatedBindings.cpp PROPERTIES
    SKIP_LINTING ON
)

Link to official CMake documentation: https://cmake.org/cmake/help/latest/prop_sf/SKIP_LINTING.html

Pre CMake 3.27

You could also just add comments to your code.

https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics

// NOLINTBEGIN
...
// NOLINTEND
like image 145
jpr42 Avatar answered Jan 31 '26 04:01

jpr42


In the directory you want to ignore, create a .clang-tidy config file, that disables all checks with:

Checks: '-*'

If there is no way of keeping such a file in a repository, the file can be easily generated before running clang-tidy with echo "Checks: '-*'" > $folder2ignore/.clang-tidy. (This will even overwrite existing .clang-tidy, effectively disabling clang-tidy for the folder)

like image 25
Vojtěch Chvojka Avatar answered Jan 31 '26 03:01

Vojtěch Chvojka