I have a few custom clang-tidy checks. For instance one in the cppcoreguidelines
module and another in the misc
module. They work fine. Now I extended clang-tidy by a custom module to organize them into.
When I rebuild, it succeeds but when I run ./clang-tidy -list-checks -checks=*
, my checks do not show up.
Here is what I did to add my custom module called sw
:
Created a subdirectory
sw
under/clang-tools-extra/clang-tidy/
Updated
/clang-tools-extra/clang-tidy/CMakeLists.txt
by:- adding
add_subdirectory(sw)
right belowadd_subdirectory(readability)
- listing
clangTidySWModule
inside theset(ALL_CLANG_TIDY_CHECKS ...)
command
- adding
Added
/clang-tools-extra/clang-tidy/sw/CMakeLists.txt
with the following content:
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)
add_clang_library(clangTidySWModule
AllCapsEnumeratorsCheck.cpp
CatchByConstReferenceCheck.cpp
SWTidyModule.cpp
LINK_LIBS
clangTidy
clangTidyUtils
DEPENDS
omp_gen
)
clang_target_link_libraries(clangTidySWModule
PRIVATE
clangAnalysis
clangAST
clangASTMatchers
clangBasic
clangLex
clangTooling
)
- Added
/clang-tools-extra/clang-tidy/sw/SWTidyModule.cpp
with the following content:
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "AllCapsEnumeratorsCheck.h"
#include "CatchByConstReferenceCheck.h"
namespace clang {
namespace tidy {
namespace sw {
class SWModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AllCapsEnumeratorsCheck>(
"sw-all-caps-enumerators");
CheckFactories.registerCheck<CatchByConstReferenceCheck>(
"sw-catch-by-const-reference");
}
};
// Register the SWModule using this statically initialized variable.
static ClangTidyModuleRegistry::Add<SWModule>
X("sw-module", "Adds my custom checks.");
} // namespace sw
// This anchor is used to force the linker to link in the generated object file
// and thus register the ReadabilityModule.
volatile int SWModuleAnchorSource = 0;
} // namespace tidy
} // namespace clang
I added the two checks all-caps-enumerators
and catch-by-const-reference
like I did under other modules before:
python3 add_new_check.py sw all-caps-enumerators
python3 add_new_check.py sw catch-by-const-reference
Am I missing something? Why are my checks not showing up?