Skip to content

Conversation

scottamplitude
Copy link
Contributor

Created built-in support for SLOC, Cyclomatic & Halstead complexity support with new CLI param complexity-strategy.

@simonrenoult
Copy link
Owner

Oh wow. Thanks for your contribution. It looks promising, I'll look into it 👍

@scottamplitude
Copy link
Contributor Author

How's this look to you @simonrenoult ?

@simonrenoult
Copy link
Owner

simonrenoult commented Sep 6, 2021

Hi @scottamplitude,

I love the idea. Two things we should consider:

  1. We loose the ability to evaluate other languages than JS/TS. While imperfect, node-sloc allowed code-complexity to support lots of languages. IMO, the Sloc strategy should keep using node-sloc while Halstead/Cyclomatic strategies should fail if the files analyzed are not JS/TS. This way we get the best of both worlds. 🥳

  2. 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 😞 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? 🤔

@scottamplitude
Copy link
Contributor Author

scottamplitude commented Sep 8, 2021

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 #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.

@scottamplitude
Copy link
Contributor Author

@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.

@simonrenoult
Copy link
Owner

Hi,

All good, thanks 👍 , 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?

@simonrenoult
Copy link
Owner

simonrenoult commented Sep 18, 2021

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 👏

@simonrenoult
Copy link
Owner

I just merged an alternative version using escomplex. Available in 4.3 :)

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

Labels

None yet

2 participants