terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.82k stars 248 forks source link

Idea needed: Javascript anonymous functions #324

Open terryyin opened 3 years ago

terryyin commented 3 years ago

It seems anonymous functions are very common in javascript (so as short lambda in other languages).

I'm wondering if it makes sense to stop counting anonymous function complexity and simply add/merge it to the named function that's containing it.

const sum = array => array.reduce((a, b)=>a+b)

becomes one function named sum with CCN 1.

What do you think?

sthagen commented 2 years ago

Sorry for being so late (I stopped using lizard for a while and still struggle to make the tool not encounter recursion overflows when visiting specific huge source trees - cf. #293).

Yes, I am in favor of taking anonymity as a hint to not consider with a made up name but instead to accumulate the complexity in the parent scope.

In real life I sometimes see "could have been translation units" wrapped into a slick little anonymous function. Now in these not so rare cases, I wonder if adding a constant wun to the overall complexity of the surrounding scope is realistic?