【问题标题】:How to ignore sonar rule to specific line of code in c#?如何在 C# 中忽略特定代码行的声纳规则?
【发布时间】:2019-10-25 14:08:48
【问题描述】:

我使用 sonarLint。我希望不对特定线路执行声纳测试。我使用了“//NOSONAR”,但它没有用。不指定错误号。

编辑:当我使用 //NOSONAR 时,错误仍然出现在 sonarlint 中。但在主项目 (SonarQube) 中不再出现错误。

【问题讨论】:

标签: c# sonarlint sonarlint-vs


【解决方案1】:

这是 Visual Studio 的建议,而不是 SonarLint 警告。另外,我相信 Visual Studio 不支持 NOSONAR。您可以在源代码中抑制:

#pragma warning disable IDE0017
<your code>
#pragma warning restore IDE0017

或在抑制文件中:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0017:Simplify object initialization", Justification = "<Pending>", Scope = "member", Target = "~M:<your class and your method>")]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 2018-03-24
    相关资源
    最近更新 更多