It is possible to configure Sonar to ignore (without #pragma warning disbale) such code lines. I Cannot break this URL into multiple lines without breaking navigation to hyperlink.
Do you have a proposed heuristic in mind – like ignoring comments that only contain URLs? I have a feeling it will be hard to find something that doesn’t add a lot of complexity to a relatively simple rule.
Keep in mind you can also mark the finding as Won’t Fix or False Positive in the SonarCloud UI.
I would be satisfied if any line with an URL is not detected by Sonar.
It doesn’t matter if the URL is inside a comment or a variable declaration or inside a method parameter.
// https://very-long-url
or
public void Main()
{
MakeRequest("https://very-long-url");
}
or
public void Main()
{
MakeRequest(
"https://very-long-url"
);
}
or
/// <summary>
/// The Foo method is called from
/// <see cref="https://very-long-url">Main</see> <---------
/// </summary>
/// <mytag>Secret stuff</mytag>
/// <param name="s">Description for s</param>
static void Foo(string s) { Console.WriteLine(s); }
We have had a look at the rule and we believe that the correct way to go is to mark it as a won’t fix in the UI. Understanding the content of the lines would slow down the rule considerably.