Skip to content

Instantly share code, notes, and snippets.

@steveh
Forked from joho/quality.rake
Created October 2, 2009 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveh/199357 to your computer and use it in GitHub Desktop.
Save steveh/199357 to your computer and use it in GitHub Desktop.
# extracted from marty andrew's presentation on ruby static code analysis
# http://www.slideshare.net/martin_j_andrews/code-quality-analysis
require 'flog'
require 'flay'
require 'roodi'
require 'roodi_task'
require 'metric_fu'
desc "Analyze for code complexity"
task :flog do
flog = Flog.new
flog.flog_files ['app', 'lib']
threshold = 40
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 "#{bad_methods.size} methods have a flog complexity > #{threshold} unless bad_methods.empty?"
end
desc "Analyze for code duplication"
task :flay do
threshold = 25
flay = Flay.new({:fuzzy => false, :verbose => false, :mass => threshold})
flay.process(*Flay.expand_dirs_to_files(['app']))
flay.report
raise "#{flay.masses.size} chunks of code have a duplicate mass > #{threshold}" unless flay.masses.empty?
end
RoodiTask.new 'roodi', ['app/**/*.rb', 'lib/**/*.rb']
task :quality => [:flog, :flay, :roodi, 'metrics:all']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment