Last active
December 18, 2015 17:29
-
-
Save billhorsman/5818994 to your computer and use it in GitHub Desktop.
Use ruby_parser gem to list all ruby files that produce an error. I'm using this to highlight Ruby files that might not be parsed successfully by Code Climate.
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
namespace :code do | |
desc "Parse with ruby_parser and list files producing errors" | |
task :parse do | |
bad = [] | |
Dir.glob("**/*.rb").each do |filename| | |
if system("ruby_parse_extract_error #{filename} > /dev/null 2>&1") | |
print "." | |
else | |
bad << filename | |
print "x" | |
end | |
STDOUT.flush | |
end | |
puts | |
puts "Found #{bad.size} bad file(s):" | |
bad.each do |filename| | |
puts " #{filename}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As @zenspider says, it's better to use
ruby_parse_extract_error
rather than rely on the output ofruby_parse
. Note that withruby_parse_extract_error
the exit code will indicate success but withruby_parse
it returns success regardless of how well it was parsed.I am using this taks because my project is in Ruby 2 but Code Climate only supports Ruby 1.9.3 at the moment (they are working on it). I'm happy to forego Ruby 2 syntax in favour of awesome reports from Code Climate about how awful my code is :)
As @codeclimate says, this task will indicate any parse failures, not just ones relating to Ruby 2 syntax in Ruby 1.9.3. Hopefully your test suite spots the other failures though... I guess this is like the simplest, most lenient test suite you could have :)
Finally, don't assume that
ruby_parse_extract_error
will always fail to parse Ruby 2 syntax.