SonarQube 无法检测 cs 代码中的重复

问题描述 投票:0回答:1

我正在测试 SonarQube,此代码存在于测试项目中:

public class Widgetor
{
    internal static int SelectValue(int ret)
    {
        switch(ret)
        {
            case 0: return 1;
            case 4: return 7;
            case -1: return 2;
            case 2: return -1;
            default: return 0;
        }
    }
    internal static int SelectValue_Copy(int ret)
    {
        switch (ret)
        {
            case 0: return 1;
            case 4: return 7;
            case -1: return 2;
            case 2: return -1;
            default: return 0;
        }
    }
}

我正在使用 MSBuild Runner 和 MSBuil 14 运行 SonarQube 版本 5.6。

我找不到任何有关如何配置我的项目以进行代码重复检测的帮助。据我所知,这应该是开箱即用的一部分。 项目概述显示“0%”重复代码。

我发现这个答案它并没有真正告诉我任何事情。

c# msbuild sonarqube
1个回答
6
投票

SonarQube Duplications 文档提供了很好的见解:

只要有至少 100 个连续且重复的标记(可以用属性 sonar.cpd.${language}.minimumTokens 覆盖)分布在至少 10 行代码上(可以用属性 sonar.cpd.${语言}.minimumLines).

因此,在示例中添加更多 case 确实会触发重复检测。

© www.soinside.com 2019 - 2024. All rights reserved.