Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bradly/157627 to your computer and use it in GitHub Desktop.

Select an option

Save bradly/157627 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
@paths_to_verify = ['./app', './lib']
def check_dir_syntax(dir)
dir.each do |f|
next if f =='.' || f == '..'
path = File.join(dir.path, f)
if File.directory?(path)
check_dir_syntax(Dir.new(path))
elsif path.split('.')[-1] == 'rake' || path.split('.')[-1] == 'rb'
file = File.new(path)
check_file_syntax(file)
file.close
end
end
end
def check_file_syntax(file)
@files_counter += 1
@bad_files << file.path unless (`ruby -c #{file.path}`).strip == 'Syntax OK'
end
def check_syntax
@start_time = Time.now
@bad_files = []
@files_counter = 0
@paths_to_verify.each do |path|
check_dir_syntax Dir.new(path)
end
puts "Checked #{@files_counter} files in #{Time.now - @start_time} seconds."
exit 1 unless @bad_files.empty?
end
check_syntax()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment