【问题标题】:SonarQube does not detect duplication in cs codeSonarQube 未检测到 cs 代码中的重复
【发布时间】:2017-01-13 16:06:27
【问题描述】:

我正在测试 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%”重复代码。

我找到了this answer,它并没有真正告诉我任何事情。

【问题讨论】:

    标签: c# msbuild sonarqube


    【解决方案1】:

    SonarQube Duplications documentation 提供了很好的见解:

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

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

    【讨论】:

      猜你喜欢
      • 2018-05-11
      • 2016-12-06
      • 1970-01-01
      • 2018-07-15
      • 2019-01-07
      • 2017-09-13
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多