C# Rule: Optional parameters should not be used

Sonarqube Version 6.1 - LGPL v3 - Community Edition.
Hi-
Could you please help us to understand the C# rule :Optional parameters should not be used. (csharpsquid:S2360)

As per rule description ,use the overloading mechanism instead of the optional parameters, but if we look at the Compliant and Noncompliant code example , the Compliant Solution is using the noncompliant code again. So if you could please take a look and help us to understand the example of given in the rule description as shown below , would be great help.

Noncompliant Code Example

void Notify(string company, string office = "QJZ") // Noncompliant
{
}

Compliant Solution

void Notify(string company)
{
  Notify(company, "QJZ");
}
void Notify(string company, string office = "QJZ")
{
}

Vish,

Looks like you’re facing an issue that was resolved quite some time ago: https://github.com/SonarSource/sonar-csharp/issues/179

I would suggest updating your instance of SonarQube to the LTS (6.7.x) or Latest (7.2) and upgrading your analyzers as well.

It appears this bug was fixed in SonarC# 5.10, and the current version of SonarC# is 7.2, compatible with SonarQube 6.7.x and later.

You can see what the current compliant/noncompliant examples are here: https://rules.sonarsource.com/csharp/RSPEC-2360

Colin

2 Likes