tags:

views:

1098

answers:

6

Does Ruby have any tools along the lines of pylint for analyzing source code for errors and simple coding standards?

Would be nice if it could be integrated with cruisecontrolrb for continuous integration.

Or does everyone write such good tests that they don't need source code checkers!

Thanks

+4  A: 

One recently-updated interesting-looking tool is Ruby Object Oriented Design Inferometer - roodi for short. It's at v1.3.0, so I'm guessing it's fairly mature.

I haven't tried it myself, because my code is of course already beyond reproach (hah).

As for test coverage (oh dear, I haven't tried this one either) there's rcov

Also (look, I am definitely going to try some of these today. One at least) you might care to take a look at flog and flay for another style checker and a refactoring candidate finder.

Mike Woodhouse
And don't forget to heckle your tests! The resources in this answer will really whip your project into shape... Especially with the release of Flay this weekend; impressive stuff.
mwilliams
+3  A: 

Check these out:

  • on Ruby Inside, an article presenting Towelie, Flay and Simian, all tools to find code duplication
  • reek: a code smell detector for Ruby
  • Roodi: checks the style of your Ruby code
  • flog: a code complexity analyzer
  • rcov: will give you a C0 (if I remember correctly) code coverage analysis. But be careful though. 100% coverage is very costly and doesn't mean perfect code.
  • heckle: changes your code in subtle manners and runs your test suite to see if it catches it. Brutal :-)

Since they're all command-line tools they can all be integrated simply as cc.rb tasks. Just whip out your regex skillz to pick the important part of the output.

I recommend you first try them out by hand to see if they play well with your codebase and if you like the info they give you. Once you find a few that give you value, then spend time integrating them in your cc.

webmat
Great answer thank you, reek looks very interesting, sorry I chose the other answer, the blog post he referenced was very thorough.
Dan Powley
+5  A: 

I reviewed a bunch of Ruby tools that are available here

http://devver.net/blog/2008/10/ruby-tools-roundup/

most of the tools were mentioned by webmat, but if you want more information I go pretty in depth with examples.

I also highly recommend using Metric-Fu it gives you a on gem/plugin install of 3 of the more popular tools and is built with cruisecontrolrb integration in mind.

The creator has a great post that should help get you up and running in no time.

http://jakescruggs.blogspot.com/2008/04/dead-simple-rails-metrics-with-metricfu.html

There has been a lot of activity in Ruby tools lately which I think is a good sign of a growing and maturing language.

danmayer
I will also take a good look at reek - http://silkandspinach.net/2008/09/23/reek-a-code-smells-detector-for-ruby/ suggested by webmat. Would you consider including it in your answer for others?
Dan Powley
Holy crap! That tools roundup looks pretty comprehensive. I'll have to check it out :-) Thanks for sharing.
webmat
A: 

There's also the built-in warnings you can enable with a quick:

ruby -w

Or setting the global variable $VERBOSE to true at any point.

Atiaxi
A: 

I just released Excellent which implements several checks on Ruby code. It combines roodi, reek and flog and also adds some Rails specific checks:

gem sources -a http://gems.github.com
sudo gem install simplabs-excellent

May be helpful...

A: 

Hi,

Out of curiosity I am interested in building a code smell detector for RoR. Can anyone suggest good guides to start?

Thanks

Robert
@Robert: This should be asked as a separate question, not as an answer. Click the **[Ask Question]** button at the top right of the page. You'll be able to provide a link back to this question if you think it's relevant.
Bill the Lizard