Hacking rake:stats to get gross LOC

Web App Autopsy has some juicy metrics such as the 100:10:1 ratio of anonymous visitors to free registered users to paying users. But they also have LOC counts which seem quite high, and which include things that rake:stats (a Rake task that’s part of Rails, which counts lines of source code and provides some basic analysis) doesn’t count. So, I hacked rake:stats to include them. Here’s what I did:

I added this code to my Rakefile:

(This code is based on this code I found that does something related.)

As you can see it doesn’t count JavaScript because the included Prototype code that’s included by default in Rails projects is huge-mungous. You can just uncomment that and see your project grow by 5KLOC if you want. Or you can temporarily delete those files, maybe in a quick ‘svn export’ temporary directory, and run rake:stats in there to see what your own JavaScript stuff contributes.

(I tried to get a fancy regex going that excluded the six files that make up Prototype, but I couldn’t get it to work quickly. I don’t care enough about that one issue to keep spending time on it, but if you figure out a clean way to get that done I’d love to see it, just post a comment.)

Hope this proves useful!

8 thoughts on “Hacking rake:stats to get gross LOC”

  1. Pretty clever code, although it negatively impacts the Code to Test Ratio numbers. Could probably hack it further and add the notion of untestable code, but this works pretty well for a quick guesstimate. Thanks!

  2. Hi Jamie,

    I added your code to my RakeFile but I’m getting this error on line 03: “no such file to load — code_statistics”. How do I get around this?

    Thanks a lot,
    SSCirrus

  3. CodeStatistics is part of Rails so it’s probably a matter of “require”-ing the right stuff in the top of your Rakefile. Mine looks like this:
    require 'rake'require 'rake/testtask'require 'rake/rdoctask'require 'tasks/rails'

Leave a Reply

Your email address will not be published. Required fields are marked *