Ruby source code analyzer (something like pylint)

2019-01-13 00:08发布

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!

7条回答
Deceive 欺骗
2楼-- · 2019-01-13 00:38

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.

查看更多
何必那么认真
3楼-- · 2019-01-13 00:46

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.

查看更多
We Are One
4楼-- · 2019-01-13 00:46

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

查看更多
聊天终结者
5楼-- · 2019-01-13 00:49

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.

查看更多
该账号已被封号
6楼-- · 2019-01-13 00:50

Code metrics on ruby toolbox website.

查看更多
混吃等死
7楼-- · 2019-01-13 01:01

Rubocop is a widely-used static code analyzer.

查看更多
登录 后发表回答