Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Created January 14, 2010 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save balinterdi/277313 to your computer and use it in GitHub Desktop.
Save balinterdi/277313 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
FILE_TYPES = ["rb", "feature", "yml", "erb", "haml"]
def rm_trailing_whitespace!(file)
trimmed = []
trimmed = File.readlines(file).map do |line|
line.gsub(/\s+$/, "")
end
open(file, "w") { |f| f.write(trimmed) }
end
root = ARGV.first
files = File.directory?(root) ? Dir.glob("#{root}/**/*.{#{FILE_TYPES.join(',')}}") : [root]
files.each { |file| rm_trailing_whitespace!(file) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment