##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.
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
Quality::Rake::Task.new { |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_glob = '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_glob =
'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'
}
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.
Quality uses semantic versioning--any incompatible changes will come out as major number updates.
Tested against Ruby >=2.0--does not support Ruby 1.9.x.
- 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.
Quality makes use of the following other gems, which do the actual checking:
- Browse the code or install the latest development version from https://github.com/apiology/quality/tree
Licensed under the MIT license.