Check return value without increasing Cognitive Complexity (SonarLint)

52 views Asked by At

I have a piece of code which is marked with a high score of cognitive complexity by SonarLint. In this piece of code functions are called and afterwards the return value is checked. So it has the following structure:

ret = func(arg_a1, arg_a2);
if(ret!=0){return ret;}
some other statements
ret = func(arg_b1, arg_b2);
if(ret!=0){return ret;}
some other statements
ret = func(arg_c1, arg_c2);
if(ret!=0){return ret;}
some other statements
ret = func(arg_d1, arg_d2);
if(ret!=0){return ret;}
some other statements
...
return 0;

In the logic of SonarLint each if clause increases the cognitive complexity by one. The cognitive complexity does not increase with calling a lot of functions, but it increases with calling a lot of functions and checking return values.

Should I just ignore coginitve complexity in this case?

0

There are 0 answers