Most of my javascript code files look like this:
(function() {
var Foo = function() {
...
};
var Bar = function() {
...
};
...
}());
I've tried a number of tools that calculate the cyclomatic complexity of code, and they all generate wrong reports (from my point of view), that is: they all point their fingers at the wrapping functions as the most complex ones.
The problem with this is that all reports are badly distorted by this fact: the wrapping functions occupy often more than half of the complexity pie chart, and all average numbers are biased.
Is there a way to obtain the real complexity of my code, not biased by the wrapper functions?
Are all those tools doing it wrong? Am I doing it wrong wrapping my code inside a function for scoping (I don't think so)? Am I doing it wrong using those tools at all?
EDIT
It was suggested to remove the wrapper function before calculating complexity, and I would be happy to do it, but is there a reliable way to do it automatically?Please just ignore this and go for a proper solution.