c++ 整齐:readability-function-cognitive-complexity.DescribeBasicIncrements值无效

xqnpmsa8  于 2023-03-25  发布在  其他
关注(0)|答案(1)|浏览(146)

https://clang.llvm.org/extra/clang-tidy/checks/readability/function-cognitive-complexity.html(示例中为function3)中提供的示例代码上运行clang-tiy时。
使用下面的命令

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是坏了还是我做错了什么?
其他信息:

  • clang版本12.0
k5ifujac

k5ifujac1#

这是你的问题的根源:
其他信息:

  • clang版本12.0

DescribeBasicIncrements选项是在this commit中引入的,它不是clang 12.0的一部分
安装最新的clang版本,它应该可以正常工作。

相关问题