Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby source code analyzer (something like pylint)

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!

like image 360
Dan Powley Avatar asked Nov 13 '08 08:11

Dan Powley


6 Answers

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.

like image 165
danmayer Avatar answered Oct 02 '22 07:10

danmayer


Check these out:

  • on Ruby Inside, an article presenting Towelie, Flay and Simian, all tools to find code duplication
    • Towelie
    • flay
    • Simian (a more general tool that supports Ruby among other languages)
  • 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.

like image 21
webmat Avatar answered Oct 02 '22 07:10

webmat


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.

like image 43
Mike Woodhouse Avatar answered Oct 02 '22 07:10

Mike Woodhouse


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.

like image 43
Atiaxi Avatar answered Oct 02 '22 08:10

Atiaxi


Code metrics on ruby toolbox website.

like image 24
Serge Avatar answered Oct 02 '22 08:10

Serge


Rubocop is a widely-used static code analyzer.

like image 30
myconode Avatar answered Oct 02 '22 06:10

myconode