ejwa / gitinspector

:bar_chart: The statistical analysis tool for git repositories
GNU General Public License v3.0
2.38k stars 328 forks source link

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

Open christo8989 opened 4 years ago

christo8989 commented 4 years ago

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;
}
adam-waldenberg commented 4 years ago

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/