gitinspector icon indicating copy to clipboard operation
gitinspector copied to clipboard

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

Open christo8989 opened this issue 4 years ago • 1 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;
}

christo8989 avatar Oct 14 '20 19:10 christo8989

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/

adam-waldenberg avatar Oct 15 '20 09:10 adam-waldenberg