【问题标题】:Refactor the code not to use Absolute Paths or URIs [closed]重构代码以不使用绝对路径或 URI [关闭]
【发布时间】:2021-04-04 10:19:28
【问题描述】:

我的 C# WIndows 窗体应用程序有一些指向 Web URI 的菜单链接。但是现在我的 SonarQube Scan 给了我这个错误/警告(S1075)来重构我的代码。那么在 C# 后端代码中使用 Web URI 的安全/最佳方式是什么。

private void HelpDocMenu_Click(object sender, EventArgs e)
{           
   System.Diagnostics.Process.Start("https://docs.google.com/document/d/142SFA/edit?usp=sharing");
}

SonarQube 错误

S1075 Refactor your code not to use hardcoded absolute paths or URIs

【问题讨论】:

  • 感谢您的帮助。可以请帮助我理解这一点。我对此并不熟悉。
  • 如果您认为这不是问题,请忽略它。 AFAIK 你不能在每行/方法的基础上禁用警告(至少当我尝试 sonarqube 时)所以忽略它或禁用它(见this 答案)。
  • 哪个警告?有消息或ID吗?
  • S1075 是代码。
  • 是的。我也是这么想的。我找不到任何解决方法。抑制这个错误将是要走的路。

标签: c# sonarqube sonarqube-scan


【解决方案1】:

您有三个选择:

  1. 忽略它:
private void HelpDocMenu_Click(object sender, EventArgs e)
{       
   #pragma warning disable S1075 // URIs should not be hardcoded    
   System.Diagnostics.Process.Start("https://docs.google.com/document/d/142SFA/edit?usp=sharing");
   #pragma warning restore S1075 // URIs should not be hardcoded
}
  1. 要有这样的临时变量:
private void HelpDocMenu_Click(object sender, EventArgs e)
{           
    var url = "https://docs.google.com/document/d/142SFA/edit?usp=sharing";
    System.Diagnostics.Process.Start(url);
}
  1. 要将其放入您的配置文件,一些 settings.json。

第三个选项是推荐的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 2013-04-17
    • 2021-10-02
    相关资源
    最近更新 更多