6.4 Custom CFG check
We are going to use the knowledge gained in Section 5.4, Custom Clang-Tidy check to create a custom CFG check. As mentioned previously, the check will use Clang’s CFG to calculate cyclomatic complexity. The check should issue a warning if the calculated complexity exceeds a threshold. This threshold will be set up as a configuration parameter, allowing us to change it during our tests. Let’s start with the creation of the project skeleton.
6.4.1 Creating the project skeleton
We will use cyclomaticcomplexity
as the name for our check, and our project skeleton can be created as follows:
$ ./clang-tools-extra/clang-tidy/add_new_check.py misc cyclomaticcomplexity
Figure 6.3: Creating a skeleton for the misc-cyclomaticcomplexity check
As a result of the run, we will get a number of modified and new files. The most important ones for us are the following two files located in the clang-tools-extra/clang-tidy/misc/
folder:
misc...