I'm a fan of the CRAP metric, and use it to monitor code quality for开发者_Python百科 my C# and Java projects.
I'd like to do the same for my growing Javascript codebase.
Is there an existing process that makes this easy to integrate into my Javascript build process?
The CRAP formula is:
var complexity = ...; //cyclomatic complexity of a method
var coverage = ...; //test code coverage for the method
var crap = Math.pow(complexity,2) * Math.pow(1 – coverage/100,3) + complexity;
So, you need to calculate the cyclomatic complexity and calculate the test code coverage (or here).
jshint calculates the cyclomatic complexity, see http://www.jshint.com/docs/ parameter maxcomplexity. I don't know, how you can retrieve the results, but you might look into the jshint sources. Hope that helps
精彩评论