While running clang-tidy on an example code provided at https://clang.llvm.org/extra/clang-tidy/checks/readability/function-cognitive-complexity.html (function3
in the examples).
with the below command
clang-tidy.exe Example.cpp -config="{Checks: '-*,readability-*',CheckOptions: [{key: readability-function-cognitive-complexity.Threshold, value: 2},{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: false} ]}"
I get below output.
\Example.cpp:2:5: warning: function 'function3' has cognitive complexity of 3 (threshold 2) [readability-function-cognitive-complexity]
int function3(bool var1, bool var2) {
^
\Example.cpp:3:3: note: +1, including nesting penalty of 0, nesting level increased to 1
if(var1) { // +1, nesting level +1
^
\Example.cpp:4:5: note: +2, including nesting penalty of 1, nesting level increased to 2
if(var2) // +2 (1 + current nesting level of 1), nesting level +1
^
\Example.cpp:4:13: warning: statement should be inside braces [readability-braces-around-statements]
if(var2) // +2 (1 + current nesting level of 1), nesting level +1
^
{
\Example.cpp:5:14: warning: 42 is a magic number; consider replacing it with a named constant [readability-magic-numbers]
return 42;
So, it seems that the key readability-function-cognitive-complexity.DescribeBasicIncrements
has no effect. I also tried with
{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: 'false'}`
{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: '0'}
{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: 0}
but still got the additional diagnostics on the lines that increase cognitive complexity. So, I think readability-function-cognitive-complexity.DescribeBasicIncrements is broken or am I doing something wrong?
Additional info:
This is the source of your problem:
Additional info:
- clang version 12.0
DescribeBasicIncrements
option was introduced in this commit which was not part of clang 12.0
Install the latest clang version and it should work as intended.