daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest May 17th, 2018 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This script crawls a file to look for commas after the last item in a list (array or hash)
  2. # this is especially useful for javascript code that will be rendered in Internet Explorer
  3. # usage: ruby comma_catcher.rb */**/*.js
  4. # ruby comma_catcher.rb foo.js
  5.  
  6. ARGV.each do |file_path|
  7.   file = File.open(file_path.strip)
  8.   set = []
  9.   file.each_with_index do |line,index|
  10.     next if line.strip == ''
  11.    
  12.     set << (index.to_s+": "+ @last_line.strip) if [")","]","}"].include?(line.strip[0,1]) and @last_line.strip[-1,1] == ","
  13.     @last_line = line
  14.   end
  15.   if set.empty?
  16.     puts "Clean: #{file_path.strip}"
  17.   else
  18.     puts "#{set.length} error(s): #{file_path.strip}"
  19.     set.each { |c| puts " * #{c}" }
  20.   end
  21. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top