Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
christo8989 opened this issue Oct 14, 2020 · 1 comment

Comments

@christo8989
Copy link

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
Copy link
Member

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants