gpt4 book ai didi

c# - 使用 Roslyn SDK 生成器生成的自定义 SonarQube 规则始终发出类型 "Code Smell"

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:49 27 4
gpt4 key购买 nike

我正在尝试使用 Roslyn SDK 生成器在 VisualStudio 2015 中创建自定义 SonarQube 规则。

生成器工作正常,我能够将 .jar 文件发布到 SonarQube 服务器并在日常构建中使用我的自定义规则。现在我想将规则归类为“漏洞”,但它总是显示为“代码味道”。

我尝试了几种方法:

  1. 将 DiagnosticDescriptor 类的“Category”更改为“Security”

    private const string Category = "Security";

    private static DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);

    public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } }
  2. 更改了生成器提供的 xml 模板并使用新的 xml 重新生成了插件(我尝试用“SECURITY”和“SECURITY_COMPLIANCE”代替生成的“MAINTENABILITY_COMPLIANCE”)

     <sqale xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <chc>
    <key>SECURITY</key>
    <chc>
    <rule-key>MyRule</rule-key>
    <prop>
    <key>remediationFunction</key>
    <txt>CONSTANT_ISSUE</txt>
    </prop>
    <prop>
    <key>offset</key>
    <txt />
    <val>15min</val>
    </prop>
    </chc>
    </chc>
    </sqale>

到目前为止没有任何效果。

我正在使用以下配置:

  • VS2015 更新 3
  • SonarQube 6.1 版
  • SonarLint 2.8 版
  • 使用 SonarQube.Roslyn.SDK v. 1.0 开发的自定义 C# 分析器

最佳答案

不幸的是,明确设置类别的能力似乎尚未实现 - 请参阅 https://jira.sonarsource.com/browse/SFSRAP-48

作为一种解决方法,您可以将标记 security 添加到规则中,由于 automatic conversion of tag into category in SonarQube,规则将被归类为 Vulnerabilty .然而,在构建 SonarQube 规则时,SonarQube.Plugins.Roslyn.RuleGenerator 似乎没有考虑 CustomTags 属性,而是添加了 newRule.Tags = diagnostic.CustomTags ?.ToArray(); 到方法 SonarQube.Plugins.Roslyn.RuleGenerator.GetAnalyzerRules并重建 sonarqube-roslyn-sdk 将完成这项工作。

关于c# - 使用 Roslyn SDK 生成器生成的自定义 SonarQube 规则始终发出类型 "Code Smell",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40637082/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com