Cognitive complexity - how to use

Hello everyone,

I am trying to understand how to use Cognitive complexity in SonarQube 7.9.
As I understand, total (summed) cognitive complexity doesn’t tell us much, we should actually track down methods with cognitive complexity over 15 and refactor them.
My problem is that in Cognitive complexity view I can see total CC on package or class level, but not on method level. Is this information available?
Also, on project level it would ten be useful to have number of methods that exceed CC limit and maybe view that lists them (as flat list or tree that includes classes and packages, but only those that contain such methods).

Any comments on that ?

Igor

Hi Igor,

Welcome to the community!

We don’t track method-level complexity as a metric. Metrics are calculated and reported at file level and above. To find the methods with a Cognitive Complexity > 15, just use the rule. Then you can get the project-wide list you’re after by filtering the Issues page by that rule:

 
HTH,
Ann

Hi Ann,

That’s exactly what I was looking for.
Thanks a lot for the helpful answer.

Regards,
Igor

1 Like