在https://clang.llvm.org/extra/clang-tidy/checks/readability-function-cognitive-complexity.html提供的示例代码上运行clang时,请参阅function3。
使用下面的命令
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} ]}"我的产量低于产量。
\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;因此,密钥readability-function-cognitive-complexity.DescribeBasicIncrements似乎没有任何影响。我也试过
{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: 'false'}`
{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: '0'}
{key: readability-function-cognitive-complexity.DescribeBasicIncrements, value: 0} 但在增加认知复杂性的线路上仍然得到了额外的诊断信息。所以,我认为readability-function-cognitive-complexity.DescribeBasicIncrements坏了,还是我做错了什么?
更多信息:
发布于 2021-07-02 20:02:30
https://stackoverflow.com/questions/68226770
复制相似问题