kisstkondoros / codemetrics

VSCode extension which shows the complexity information for TypeScript class members
Other
404 stars 20 forks source link

With default config complexity and recommendations are outrageous #83

Closed FirstWhack closed 1 year ago

FirstWhack commented 4 years ago

The following reports "Complexity is 6 it's time to do something..."

function thing(foo, bar) {
  if (foo) {
    return 'foo';
  } else if (bar) {
    return 'bar';
  }
}

This piece of code has an obvious cyclomatic complexity of 3.. Aside from the contrived nature of this code, it is not time to do something.

Per the readme:

Please note that it is not a standard metric, but it is a close approximation of Cyclomatic complexity.

I have another example where the actual cyclomatic complexity of a generator function (in a redux saga) is 58, but the tool reports complexity of 7. It is 200 lines of conditional yields and essentially the same complexity as the above example according to CodeMetrics. I will have to take some time to recreate it in a readable but unlicensed way later.

kisstkondoros commented 4 years ago

I'm open for suggestions on how to improve the situation, however I think that code path could be simplified (that is the purpose of this extension, to point out such things) The reason for having the same result as the mentioned generator function is likely that yields are not counted at the moment.

I'm not sure though about what is the purpose of this issue report... yes it is not cyclomatic complexity as it is stated in the readme, yes it is imperfect, on the other hand almost every aspect of the complexity computation can be customized with a simple configuration.

You don't like that return statements add +1? Set the value associated with them to 0.

I'll keep this open so that I'll add +1 for yields as well to be consistent

spartanatreyu commented 3 years ago

I think issue: Support for Cognitive Complexity #96 will go a long way to sorting out this confusion.

fjqingyou commented 2 years ago

if with else statement is 2.

but, i found an default setting 'Codemetrics › Luaconfiguration: Elseif Clause' is 1

It seems that ‘else if’ are recognized as ‘else’ and ‘if’ respectively, so it leads to 2? I think it might be more appropriate to keep it at 1

kisstkondoros commented 1 year ago

Changed default for IfWithElseStatement to 1 available in kisstkondoros.vscode-codemetrics v1.26.1