Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Created April 18, 2012 23:22
Show Gist options
  • Select an option

  • Save cstrahan/2417318 to your computer and use it in GitHub Desktop.

Select an option

Save cstrahan/2417318 to your computer and use it in GitHub Desktop.
A hackish rake task for checking code quality with reek and cane.
# Colors
escape = -> n { STDOUT.tty? ? "\033[#{n}m" : "" }
red = escape[31]
green = escape[32]
yellow = escape[33]
blue = escape[34]
magenta = escape[35]
cyan = escape[36]
reset = escape[ 0]
desc "Runs reek and cane."
task :quality do
puts yellow + "Cane " + "=" * 10 + reset
puts `cane --style-glob="{app,lib}/**/*.rb"`
# Because reek's output isn't the nicest.
puts yellow + "Reek " + "=" * 10 + reset
rbfiles = Dir.glob("{app,lib}/**/*.rb").join(" ")
reek = `reek -q #{rbfiles} 2>&1`.split(/\r|\n/).reject(&:empty?)
reek.select! do |line|
#line.index("warning") || line.index("UncommunicativeVariableName") || line.index("TooManyStatements")
true
end
reek_files = {}
file = nil
reek.each do |line|
this_line_is_warning = !line.start_with?(" ") && line.index("warning")
file = line.gsub(/ --.*/, '') if this_line_is_warning
unless file.nil? || this_line_is_warning
(reek_files[file] ||= []) << line
end
end
reek = []
reek_files.keys.each do |file|
reek << ""
reek << green + file + reset
reek_files[file].each do |problem|
problem = problem.gsub(/ [^ ]+/) { |s| blue + s + reset }
reek << problem
end
end
reek = reek.drop(1)
puts reek
end
@j3j3
Copy link
Copy Markdown

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment