Automatic Code Quality Tool for Ruby

Automatic code quality tool for Ruby?

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

  • Saikuro
  • Roodi
  • Flog

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

Gems to assist in monitoring code quality

I use the following myself. I've found rubycritic particularly useful, and I believe it is the gem underlying a lot of the Code Climate reviews.

The sandi_meter is one I haven't used as much, but strongly encourages smaller methods.

I also strongly encourage using simplecov to help you evaluate your code coverage. Code coverage is by no means a panacea for any code problem, but it'll at least ensure that you do not miss segments of your code altogether.

The full list:

  gem 'traceroute' # Checks for undefined routes and unreachable actions.
gem 'bullet' # Checks for query optimizations.
gem 'rails_best_practices' # Checks for code optimization.
gem 'rubycritic' # Checks for code optimization.
gem 'sandi_meter' # Checks for compliance to Sandi Metz's rules for developers.
gem 'simplecov' #Enables coverage analysis of code.

Automated code sanity check tools for Ruby

The metric_fu gem might be perfect for what you need. From it's README: "Metric-fu is a set of rake tasks that make it easy to generate metrics reports. It uses Saikuro, Flog, Rcov, and Rails'
built-in stats task to create a series of reports. It's designed to integrate easily with CruiseControl.rb by placing files in the Custom Build Artifacts folder." Since they converted it to a gem, it works with non-Rails applications as well. I'll bet you could add hooks for other tools as well.

tool to scan ruby code files for repeating or similar code chunks

You can look at flay: https://github.com/seattlerb/flay
From the docs:

Flay analyzes code for structural similarities. Differences in literal
values, variable, class, method names, whitespace, programming style,
braces vs do/end, etc are all ignored. Making this totally rad.

Or, depending on your budget, you can create an account with one of the hosted static code analysis services and push your code there for a checkup.

Java has FindBugs. What is equivalent for Ruby?

Take a look at this blog. It talks about different tools (Roodi, Dust and Flog).

Tool like metric_fu or codeclimate.com for Clojure

I'm not aware of tools such as the metric_fu or codeclimate.com you mentioned for Clojure.

However, there is kibit which is "a static code analyzer for Clojure which uses core.logic to search for patterns of code for which there might exist a more idiomatic function or macro".

Also, if you are using Leiningen for Clojure development, there are a rich number of plug-ins, some of which relate to code-quality or code visualization and introspection: for example, lein-bikeshed, lein-vanity, and lein-clique.

In addition, if you develop on Eclipse with the CounterClockwise, you may try some of the Java code metric plug-ins to see if they can give you any useful reports for Clojure (note: this may be limited to lines of code if anything). Here is a recent post on Eclipse plugins for the Juno version of Eclipse related to code metrics.

Is there a way to preprocess ruby code and find errors that would occur runtime?

Unfortunately, the Halting Problem, Rice's Theorem, and all the other Undecidability and Uncomputability Results tell us that it is simply impossible in the general case to statically determine any "interesting" property about the runtime behavior of a program. We cannot even statically determine something as simple as "will it halt", so how are we going to determine "is bug-free"?

There are certain things that can be statically determined, and there are certain restricted programs for which some interesting properties can be statically determined, but largely, this is not possible. And even to the small extent that it is possible, it generally requires the language to be specifically designed to be easy to statically analyze (which Ruby isn't).

That being said, there are certain tools that contain certain heuristics to point out code that may have problems. There are certain coding standards that may help avoid bugs, and there are tools to enforce those coding standards. Keywords to search for are "code quality tools", "linter", "static analyzer", etc. You have already been given examples in the other answers and comments, and given those examples and these keywords, you'll likely find more.

However, I also wanted to discuss something you wrote:

we are forced to produce at a ridiculous pace we don't have 100% code coverage

That's a problem, which has to be approached from two sides:

  1. Practice, practice, practice. You need to practice testing and writing high-quality code until it is so naturally to you that not doing it actually ends up being harder and slower. It should become second nature to you, such that under pressure when your mind goes blank, the only thing you know is to write tests and write well-designed, well-factored, high-quality code. Note: I'm talking about deliberate practice, which means setting time aside to really practice … and practice is practice, it's not work, it's not fun, it's not hobby, if you don't delete the code you wrote immediately after you have written it, you are not practicing, you are working.
  2. Sustainable Pace. You should never develop faster than the pace you could sustain indefinitely while still producing well-tested, well-designed, well-factored, high-quality code, having a fulfilling social life, no stress, plenty of free time, etc. This is something that has to be backed and supported and understood by management.

PL/SQL pre-compile and Code Quality checks in an automated build environment?

I think that this blog describes the needed process:

http://www.theserverlabs.com/blog/?p=435

Please check and let me know what you think about it.



Related Topics



Leave a reply



Submit