ejwa / gitinspector

:bar_chart: The statistical analysis tool for git repositories

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add: The following files have an elevated cognitive complexity (in order of severity)

christo8989 opened this issue · comments

I like to analyze code by the cognitive complexity standard. It would be cool to have this section in addition to cyclomatic complexity.

https://docs.codeclimate.com/docs/cognitive-complexity

A method's cognitive complexity is based on a few simple rules:

  1. Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  2. Code is considered more complex for each "break in the linear flow of the code"
  3. Code is considered more complex when "flow breaking structures are nested"

Example:

Complex

function count(a, b, c) {
  var total = 0;
  var nums = [a, b, c];
  
  for (var i = 0; i < nums.length; i++) {
    total += nums[i];
  }
  
  return total;
}

Not Complex

function count(a, b, c) {
  var total = 0;

  total += a;
  total += b;
  total += c;
  
  return total;
}

Hi @christo8989. For what we are targeting with gitinspector this may indeed be a very useful metric... Found this article comparing cyclomatic and cognitive complexity,

https://tomasvotruba.com/blog/2018/05/21/is-your-code-readable-by-humans-cognitive-complexity-tells-you/