Build Status Coverage Status

Quality -- code quality ratchet for Ruby

Overview

Quality is a tool that runs quality checks on Ruby code using cane, reek, flog, flay and rubocop and makes sure your numbers don't get any worse over time.

Why

See this post or these slides for more information on the problem the quality gem solves.

How to use

$ gem install quality

or in your Gemfile:

group :development do
  gem 'quality'
end

and then:

$ bundle install

Once you have the gem, configure your Rakefile like this:

require 'quality/rake/task'

Quality::Rake::Task.new

Then run:

$ rake quality

If you want to ratchet up the quality and force yourself to improve code, run:

$ rake ratchet

Configuration options

Quality::Rake::Task.new do |t|
  # Name of quality task.
  # Defaults to :quality.
  t.quality_name = 'quality'

  # Name of ratchet task.
  # Defaults to :ratchet.
  t.ratchet_name = 'ratchet'

  # Array of strings describing tools to be skipped--e.g., ["cane"]
  #
  # Defaults to []
  t.skip_tools = []

  # Log command executation
  #
  # Defaults to false
  t.verbose = false

  # Array of directory names which contain ruby files to analyze.
  #
  # Defaults to %w(app lib test spec feature), which translates to
  # *.rb in the base directory, as well as those directories.
  t.ruby_dirs = %w(app lib test spec feature)

  # Array of directory names which contain any type of source files to
  # analyze.
  #
  # Defaults to t.ruby_dirs
  t.source_dirs.concat(%w(MyProject MyProjectTests))

  # Pick any extra files that are source files, but may not have
  # extensions--defaults to %w(Rakefile Dockerfile)
  t.extra_source_files = ['tools/check-script', 'Rakefile']

  # Pick any extra files that are source files, but may not have
  # extensions--defaults to %w(Rakefile)
  t.extra_ruby_files = ['Rakefile']

  # Exclude the specified list of files--defaults to ['db/schema.rb']
  t.exclude_files = ['lib/whatever/imported_file.rb',
                     'lib/vendor/someone_else_fault.rb']

  # Alternately, express it as a glob:

  # Exclude the specified list of files
  t.source_files_exclude_glob =
    '{lib/whatever/imported_file.rb,lib/vendor/**/*.rb}'

  # Extensions for Ruby language files--defaults to rb,rake
  t.ruby_file_extensions_arr = %w(rb rake)

  # Extensions for all source files--defaults to
  # rb,rake,swift,cpp,c,java,py,clj,cljs,scala,js,yml,sh,json
  t.source_file_extensions_arr =
    %w(rb rake swift cpp c java py clj cljs scala js yml sh json)

  # Relative path to output directory where *_high_water_mark
  # files will be read/written
  #
  # Defaults to 'metrics'
  t.output_dir = 'metrics'

  # Pipe-separated regexp string describing what to look for in
  # files as 'todo'-like 'punchlist' comments.
  #
  # Defaults to 'XXX|TODO'
  t.punchlist_regexp = 'XXX|TODO'
end

Code coverage

You can pull a similar trick with code coverage using SimpleCov in Ruby--put 'simplecov' in your Gemfile, and add the code below into your test_helper.rb or spec_helper.rb.

require 'simplecov'
SimpleCov.start
SimpleCov.refuse_coverage_drop

After your first run, check in your coverage/.last_run.json.

Maturity

Quality uses semantic versioning--any incompatible changes will come out as major number updates.

Supported Ruby Versions

Tested against Ruby >=2.0--does not support Ruby 1.9.x.

Contributing

  • Fork the repo
  • Create a feature branch
  • Submit a github pull request

Many thanks to all contributors, especially @andyw8, who has contributed some great improvements.

Dependencies

Quality makes use of the following other gems, which do the actual checking:

Learn More

License

Licensed under the MIT license.