5.4 Custom Clang-Tidy check
In this part of the chapter, we will transform our plugin example (see Section 4.6, Clang plugin project) into a Clang-Tidy check. This check will estimate the complexity of a C++ class based on the number of methods it contains. We will define a threshold as a parameter for the check.
Clang-Tidy offers a tool designed to aid in the creation of checks. Let’s begin by creating a skeleton for our check.
5.4.1 Creating a skeleton for the check
Clang-Tidy provides a specific Python script, add
_new
_check.py
, to assist in creating new checks. This script is located in the clang-tools-extra/clang-tidy
directory. The script requires two positional parameters:
module
: This refers to the module directory where the new tidy check will be placed. In our case, this will bemisc
.check
: This is the name of the new tidy check to add. For our purposes, we will name itclasschecker
.
By running the script in the llvm-project
directory (which contains the...