Created
August 17, 2009 18:47
-
-
Save spicycode/169298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require 'flog' | |
require 'flay' | |
require 'reek/rake_task' | |
namespace :quality do | |
desc "Analyze for code complexity" | |
task :flog do | |
flog = Flog.new :methods => true | |
flog.flog ['app', 'lib'] | |
threshold = 45 | |
bad_methods = flog.totals.select do |name, score| | |
score > threshold | |
end | |
bad_methods.sort { |a,b| a[1] <=> b[1] }.each do |name, score| | |
puts "%8.1f: %s" % [score, name] | |
end | |
raise "Flog found #{bad_methods.size} methods with a complexity > #{threshold}" unless bad_methods.empty? | |
end | |
desc "Analyze for code duplication" | |
task :flay do | |
threshold = 70 | |
flay = Flay.new(:fuzzy => false, :diff => true, :summary => false, :verbose => false, :mass => threshold) | |
flay.process(*Dir["app/**/*.rb", "lib/**/*.rb"]) | |
flay.report | |
raise "Flay found #{flay.masses.size} chunks of code have a duplicate mass > #{threshold}" unless flay.masses.empty? | |
end | |
desc "Analyze code for smelliness" | |
Reek::RakeTask.new do |t| | |
t.fail_on_error = true | |
t.verbose = false | |
t.source_files = Dir["app/models/*.rb", "lib/**/*.rb"] | |
end | |
end | |
desc "Run all quality related tasks" | |
task :quality => ['quality:flog', 'quality:flay', 'quality:reek'] | |
rescue LoadError | |
task :quality do | |
puts "Unable to find flog, flay, or reek" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment