code-complexity icon indicating copy to clipboard operation
code-complexity copied to clipboard

Add a way to compute complexity based on something else than sloc

Open simonrenoult opened this issue 5 years ago • 5 comments

What problem are you trying to solve?

We're currently measuring complexity based on sloc. It's nice but a long file doesn't always mean it's complex.

Describe the feature

We could add a --complexity-strategy=<sloc or cyclomatic or xyz> that would be used in the complexity processing.

simonrenoult avatar May 03 '20 09:05 simonrenoult

The algorithm just counts lines of code and returns that as complexity then? Would be good to have that in the readme. Looks like it comes from here: const result = await nodeSloc({ path: absolutePath }); Can open a PR for the README adjustment if you will confirm.

davemcg3 avatar Sep 15 '20 00:09 davemcg3

Added PR to cover the above: https://github.com/simonrenoult/code-complexity/pull/24

davemcg3 avatar Jul 13 '21 00:07 davemcg3

Seems fair. I changed the wording a bit and merged it, thanks :+1:

simonrenoult avatar Jul 14 '21 00:07 simonrenoult

Candidates:

  • https://www.npmjs.com/package/escomplex
  • https://eslint.org/docs/rules/complexity and its source https://github.com/eslint/eslint/blob/master/lib/rules/complexity.js

simonrenoult avatar Aug 09 '21 08:08 simonrenoult

Added PR to cover the requested functionality: #28

The PR covers adding the following complexity strategies:

  • SLOC
  • Cyclomatic
  • Halstead

Code adapted from: https://github.com/anandundavia/ts-complex

scottamplitude avatar Aug 24 '21 05:08 scottamplitude

Done in 4.3 :)

simonrenoult avatar Nov 11 '22 11:11 simonrenoult