SonarLint not reporting S3776 - Cognitive Complexity of methods should not be too high

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 :wink:

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;
    }

Hi @David_Schwartz. Welcome to the community.

The issue appears for me in VS2017 (v15.9.20):
image.

Does the issue appear if you open the file containing the issue in the editor? By default VS only analyses open files for performance reasons. If you want to analyse all files you have to Enable full solution analysis in the options. See the MS docs for more information.

It does not appear even if I open the file.

I upgraded my VS 2017 to 15.9.23 and it still doesn’t show up. Could it be a setting in Visual Studio that is blocking it?

Is there a log I can use to find the issue?