lib/bad_encodings.rb in bad_encodings-ruby19-0.1.2 vs lib/bad_encodings.rb in bad_encodings-ruby19-1.0.0

- old
+ new

@@ -1,20 +1,20 @@ require 'find' class BadEncodings class << self - def find_lines_in_path(dir, includes = nil, dir_excludes = nil) - includes ||= /(\.rb|\.rake|\.haml|\.sass|\.erb)$/ + def find_lines_in_path(dir, file_extensions = ["rb|rake|haml|sass|erb"], dir_excludes = nil) + regex = /#{file_extensions.join('|')}$/ files = [] Find.find(dir) do |path| if FileTest.directory?(path) if !dir_excludes.nil? && path =~ dir_excludes Find.prune # Don't look any further into this directory. else next end - elsif path =~ includes + elsif path =~ regex files << path end end find_lines_in_files(files.reverse) end @@ -26,10 +26,11 @@ end bad_lines end def find_lines_in_file(file) + puts "#{file}" if ENV['VERBOSE'] bad_lines = [] file = File.open(file, "r:US-ASCII") file.each_line do |line| begin if (file.lineno == 1 || file.lineno == 2) && line =~ /^#.*coding:\s([\w-]+)/ @@ -38,9 +39,10 @@ rescue ArgumentError # regex match will fail with 'invalid byte sequence in US-ASCII' # if invalid byte sequence on first line of file end next if line.valid_encoding? + puts "Bad encoding found: line #{file.lineno}" if ENV['VERBOSE'] bad_lines << [file.path, file.lineno] end bad_lines end \ No newline at end of file