6

I'm a fan of the CRAP metric, and use it to monitor code quality for 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?

casperOne
  • 73,706
  • 19
  • 184
  • 253
David Laing
  • 7,605
  • 10
  • 33
  • 44

2 Answers2

0

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

afx
  • 853
  • 1
  • 9
  • 11
0

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

Community
  • 1
  • 1
Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • 1
    I'm aware of the formula; I was hoping there was a pre-existing tool available that applied it to Javascript. Looks like extending a test running tool like JSTestDriver is the most promising option available. – David Laing Jan 01 '11 at 10:33