Sha256: 5ac125be8834aaedf8de91db2c24bda1d3d1483480efaafc194db4e1f4a819dd
Contents?: true
Size: 1.14 KB
Versions: 30
Compression:
Stored size: 1.14 KB
Contents
#!/usr/bin/env ruby require 'fileutils' def filelint(filename, fix = false) newfile = '' File.open(filename) do |file| file.readlines.each_with_index do |line, lineno| # do some checking so we can print warnings if line =~ /[ \t]$/ puts "#{filename}:#{lineno+1} Trailing whitespace" end if line =~ /\r\n?$/ puts "#{filename}:#{lineno+1} Incorrect line ending" elsif line[-1] != ?\n puts "#{filename}:#{lineno+1} No trailing newline" end # now just rstrip the line and shove it in the array # this will strip trailing whitespace and normalize line endings for us # the above stuff is simply so you know when you screwed up newfile << line.rstrip << "\n" end end if fix && File.read(filename) != newfile newname = ".#{filename}.new" File::unlink("#{filename}~") rescue nil File.open(newname,'w') { |f| f.write(newfile) } stat = File.stat(filename) File.chmod(stat.mode, newname) FileUtils.ln filename, "#{filename}~" FileUtils.ln newname, filename, :force => true File::unlink(newname) end end ARGV.each do |f| filelint(f,true) end
Version data entries
30 entries across 30 versions & 1 rubygems