Automatic code quality tool for Ruby? [closed]

2019-01-30 05:07发布

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.

9条回答
甜甜的少女心
2楼-- · 2019-01-30 05:44

There is also excellent. I haven't tried it yet, but it too looks promising.

查看更多
贪生不怕死
3楼-- · 2019-01-30 05:45

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.

查看更多
家丑人穷心不美
4楼-- · 2019-01-30 05:47

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.

查看更多
登录 后发表回答