0

My C# WIndows Forms Application has some menu links which point out to web URIs. But now my SonarQube Scan is giving me this error/warning(S1075) to refactor my code. So what would be the safe/best way to use web URI inside C# backend code.

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

SonarQube Error

S1075 Refactor your code not to use hardcoded absolute paths or URIs
Supunsam
  • 369
  • 7
  • 16
  • Thanks for the help. Can please help me to understand that. I'm not familiar with that. – Supunsam Dec 27 '20 at 09:01
  • 1
    Just ignore it if you do not think it's an issue. AFAIK you can't disable warnings on per line/method basis (at least when i tried out sonarqube) so ignore it or disable it (see [this](https://stackoverflow.com/a/34041849) answer). – Streamline Dec 27 '20 at 09:01
  • Which warning? Is there a message or an ID? – Saber Dec 27 '20 at 09:08
  • S1075 is the code. – Supunsam Dec 27 '20 at 09:20
  • Yes. I'm thinking the same. I was unable to find any workaround for this. Suppressing this error would be the way to go. – Supunsam Dec 27 '20 at 09:21
  • Hi Everyone. This question got closed due to lack of clarity. I have edited the question. If anyone feels it's clear please reopen the question as I am unable to post any more questions due to this matter. – Supunsam Jan 13 '21 at 07:28

1 Answers1

9

You have three options:

  1. To ignore it:
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. To have a temporary variable like this:
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. To put it in your configuration file, some settings.json.

Third option is the recommended one.

Boris
  • 146
  • 2
  • 5