Question

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

It 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!

Was it helpful?

Solution

I reviewed a bunch of Ruby tools that are available here

http://devver.wordpress.com/2008/10/03/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.

OTHER TIPS

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.

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.

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.

Code metrics on ruby toolbox website.

Rubocop is a widely-used static code analyzer.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top