Paluy on Miscellaneous

Of course I'm an optimist - I don't see much point in being anything else. - Winston Churchill

Rails Code Quality Tools

The only valid measurement of code quality: WTFs/minute
source

I would like to cover code quality tools I use while developing Rails applications.

Of course you should try CodeClimate service to monitor your project, but…

Let`s overview some open source solutions:

1. Rails Best Practises - RBP

It’s a static code analysis tool that checks the quality of rails code. It can be customized for your needs and even add your own checklist

I prefer to add RBP analysis to CI tasks, as following:

1
rails_best_practices -f html --template config/my_rails_best_practices.html.erb .

while I use my custom RBP template report config/my_rails_best_practices.html.erb. The RBP report is a part of my CI artifacts.

Alternative 1: ROODI - Ruby Object Oriented Design Inferometer. Usage: roodi -config=config/roodi.yml "app/**/*.rb" "lib/**/*.rb" > roodi_report.txt

Alternative 2: Rubocop

Alternative 3: Cane

Alternative 4: Ruby Lint

2. Code Coverage - SimpleCov

Add the following code to spec_helper.rb

1
2
3
4
5
6
7
8
require 'rubygems'

if ENV["COVERAGE"]
  require 'simplecov'
  SimpleCov.start 'rails'
end

# ...

Note: Add export COVERAGE=true before you run your tests.

3. Ruby Style Guide, Rails Style Guide and JavaScript Guide

Your team should apply those guides or define your own. You should also check those Github guides.

4. Rails Security Scanner - Brakeman

Note:

Read this blog post by CodeClimate

Comments