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

Version Path
typo-5.5 script/spacecheck
typo-5.4.4 script/spacecheck
typo-5.4.3 script/spacecheck
typo-5.4.2 script/spacecheck
typo-5.4.1 script/spacecheck
typo-5.4 script/spacecheck
typo-3.99.0 script/spacecheck
typo-3.99.2 script/spacecheck
typo-3.99.1 script/spacecheck
typo-3.99.3 script/spacecheck
typo-4.0.2 script/spacecheck
typo-3.99.4 script/spacecheck
typo-4.0.1 script/spacecheck
typo-4.0.0 script/spacecheck
typo-4.1.1 script/spacecheck
typo-4.0.3 script/spacecheck
typo-4.1 script/spacecheck
typo-5.0.1 script/spacecheck
typo-5.0.2 script/spacecheck
typo-5.0.3.98.1 script/spacecheck