Skip to content

Instantly share code, notes, and snippets.

@kplawver
Last active July 24, 2018 16:49
Show Gist options
  • Save kplawver/2883bc48c7f07dda7a405439d5ee66ab to your computer and use it in GitHub Desktop.
Save kplawver/2883bc48c7f07dda7a405439d5ee66ab to your computer and use it in GitHub Desktop.
desc "Checks ruby syntax on all files"
task :syntax_check do
puts "#{Dir.pwd}"
current_dir = Dir.pwd
files = []
["app", "config", "lib", "experiments", "spec"].each do |dir|
files = files + Dir.glob("#{current_dir}/#{dir}/**/*.rb")
end
puts "Testing #{files.length} files:"
success = 0
failed = 0
puts "--------"
files.each do |path|
out = `ruby -c #{path}`.strip
if !out.include?("Syntax OK")
puts "- #{path.remove(current_dir)}: #{out}"
failed += 1
else
success += 1
end
end
puts "--------"
puts "#{success} Successful, #{failed} Failed"
end
@kplawver
Copy link
Author

I ran into an issue where I was getting a stack trace way farther down than the actual error with rspec. So, I wrote this thing to syntax check every file that matters in a Rails app. It only prints files that fail, but will give you a total of successful checks.

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