views:

1127

answers:

5

One thing I really miss about Java is the tool support. FindBugs, Checkstyle and PMD made for a holy trinity of code quality metrics and automatic bug checking.

Is there anything that will check for simple bugs and / or style violations of Ruby code? Bonus points if I can adapt it for frameworks such as Rails so that Rails idioms are adhered to.

+2  A: 

Dust looks like it can help you find unused and useless code, which seems like it sort-of fits what you're after.

I'm not aware of any other such tools.
This problem is vastly harder to address in ruby than it is in java - you'll note that all those java tools brand themselves as using 'static analysis' of the code.
Static analysis of ruby code often isn't possible, because there isn't anything static that you can analyze (methods often get created at runtime and so on)

At any rate, some of these things are unneeded in ruby because the language builds them in. For example, you don't need a coding standard to enforce that your classes are all NamedLikeThis because the code won't work if they aren't.

P.S. I have to add the standard disclaimer that those kind of tools can often be a bit of a red herring. You can spend all day making your code adhere to what the tool thinks it should be, and end up with more bugs than you started with.
IMHO the best solution is to write your code fluently so you can read it more easily. No amount of static analysis is going to be as good as a human reading code which clearly states what it is meant to do. Being able to do this is where ruby is light-years ahead of many other languages. I personally would recommend you aim your efforts at learning how to write more fluently, and educating your team about such things, than spending time on static analysis.

Orion Edwards
Writing fluently and educating the team is certainly a goal; however, when idioms change (for example ENV['RAILS_ENV'] == 'development' to Rails.env.development?) then these kinds of tools can be very helpful in preventing bad habits from getting a start.
Will Sargent
+8  A: 

I've recently started looking for something like this for Ruby. What I've run across so far:

These might be places to start. Unfortunately I haven't used any of the three enough yet to offer a good opinion.

Austin
+2  A: 

Saikuro and Flog can be good for getting a basic idea of code complexity. You can also use a tool like rcov to look at your test coverage.
There is a plugin for Rails projects that combine all those metrics into a single rake task. It is called metric_fu.

ScottD
+1  A: 

I didn't see this questions when asked, but a blog post I did might help as well. In it I cover a bunch of Ruby tools and specifically cover 4 code quality tools...

Roodi Dust Flog Saikuro

It might also be worth checking out Towelie and Flay

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

Now we have combined a lot of tools into an only Ruby code quality and metrics monitoring tool called Caliper. This might fit your needs well. It tracks various quality metrics over the life of a project.

Caliper - improve your Ruby code

danmayer
+2  A: 

Another nice tool, although in early stages according to the author is reek:

http://reek.rubyforge.org/

reek currently includes very naive checks for the following code smells:

  • Long Method
  • Large Class
  • Feature Envy
  • Uncommunicative Name
  • Long Parameter List
  • Utility Function
  • Nested Iterators
  • Control Couple
  • Duplication
  • List item

Personally I think it still has too much false positives, but just looking at the output in some of my code helped me rethink some decisions about code style and architecture.

krusty.ar