code-complexity
code-complexity copied to clipboard
Added support for choosing complexity strategies
Created built-in support for SLOC, Cyclomatic & Halstead complexity support with new CLI param complexity-strategy.
Oh wow. Thanks for your contribution. It looks promising, I'll look into it :+1:
How's this look to you @simonrenoult ?
Hi @scottamplitude,
I love the idea. Two things we should consider:
-
We loose the ability to evaluate other languages than JS/TS. While imperfect,
node-slocallowedcode-complexityto support lots of languages. IMO, the Sloc strategy should keep usingnode-slocwhile Halstead/Cyclomatic strategies should fail if the files analyzed are not JS/TS. This way we get the best of both worlds. :partying_face: -
Writing our own Halstead/Cyclomatic analyzers implies that we will maintain them. I would rather use an npm package for that but it doesn't seem like it exists off the shelf :disappointed: However, I consider the added-value of theses strategies too good to miss so I'll happily welcome them. I'll reach out the ts-complex people to see if we can sort something out.
Also, it feels like the PR lacks proper tests. We could unit test the strategies, wdyt? :thinking:
All great points. I hadn't realized the intent was to support non-JS/TS based languages. Totally understandable that this would be the wrong route then.
One note RE: # 2 I initially tried implementing the new complexity strategies with https://github.com/escomplex/escomplex since you'd mentioned it in https://github.com/simonrenoult/code-complexity/issues/5, but was unable to get it working. I could spend some more time looking into it again to see if I missed something. If you have any other libraries in mind that you want to leverage, I could look into those as well.
+1 to tests for each strategy.
@simonrenoult hope all is well! Are you evaluating some third-party open source solutions for supporting these new strategies? If you've found a library or a couple of libraries you'd like to use I'd be happy to work with you to implement them in your codebase. Just let me know what you picked and I'll update this PR or create a new one.
Hi,
All good, thanks :+1: , I hope you are good as well. I think we can forget externalizing the strategies for now, it's not the priority. My others remarks remain (using node-sloc for the sloc strategy + checking for js/ts when using halstead/cyclocmatic strategies + unit tests on halstead and cyclomatic) if that's good for you. Wdyt?
I took the liberty to fork your PR in order to implement my own feedbacks: #30
It's quite close to being done. I just need to add a few unit tests on the complexity calculation and a way to choose one of the halstead metric from the CLI.
Awesome work btw, it really helped me grasp how to implement cyclomatic and halstead strategies :clap:
I just merged an alternative version using escomplex. Available in 4.3 :)