SonarQube: 8.2.0.32929
SonarLint for VS: 4.21.0.16909
Visual Studio: 2017
SonarQube correctly flags methods with Cognitive Complexity > 15. However, when creating the same class in Visual Studio 2017, Sonar Lint does not indicate any issues. This occurs both in connected and non connected mode and without any special settings for rules.
Can anyone help me get this working? I want to allow the developers to see all issues in Visual Studio, not simply find out after attempting to check in.
Steps to Reproduce: Put this sample code in Visual Studio with SonarLine
Sample code that should Report S3776 - Based on code that was flagged by our SonarQube… Modified to protect the involved partied
public int MySampleFunction(string value, object myClass)
{
var opt = myClass as MyBase;
if (opt != null)
{
int count = opt.theArray.Length;
for (int idx = 0; idx < count; idx++)
{
var item = opt.theArray[idx];
if (item is MyDerived)
{
if (item.ToString() == value)
return idx;
}
else if (item is MyBase)
{
var baseItem = item as MyBase;
if (baseItem.theArray.Length != 0)
{
if (baseItem.theArray[idx].ToString() == value)
return idx;
}
}
}
}
return -1;
}