Skip to content

Instantly share code, notes, and snippets.

@krunal
Forked from NARKOZ/whitespace.rake
Last active August 29, 2015 14:11
Show Gist options
  • Save krunal/014846048149ff529ae3 to your computer and use it in GitHub Desktop.
Save krunal/014846048149ff529ae3 to your computer and use it in GitHub Desktop.
# requires BSD sed
namespace :whitespace do
desc 'Removes trailing whitespace'
task :cleanup do
sh %{for f in `find . -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i '' 's/ *$//g' "$f";
done}, {:verbose => false}
puts "Task cleanup done"
end
desc 'Converts hard-tabs into two-space soft-tabs'
task :retab do
sh %{for f in `find . -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i '' 's/\t/ /g' "$f";
done}, {:verbose => false}
puts "Task retab done"
end
desc 'Remove consecutive blank lines'
task :scrub_gratuitous_newlines do
sh %{for f in `find . -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i '' '/./,/^$/!d' "$f";
done}, {:verbose => false}
puts "Task scrub_gratuitous_newlines done"
end
desc 'Execute all WHITESPACE tasks'
task :all do
Rake::Task['whitespace:cleanup'].execute
Rake::Task['whitespace:retab'].execute
Rake::Task['whitespace:scrub_gratuitous_newlines'].execute
end
end
# requires GNU sed
namespace :whitespace do
desc 'Removes trailing whitespace'
task :cleanup do
path = ENV['path'].present? ? ENV['path'] : '.'
sh %{for f in `find #{path} -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i 's/[ \t]*$//' $f;
done}, {:verbose => false}
puts "Task cleanup done"
end
desc 'Converts hard-tabs into two-space soft-tabs'
task :retab do
path = ENV['path'].present? ? ENV['path'] : '.'
sh %{for f in `find #{path} -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i 's/\t/ /g' $f;
done}, {:verbose => false}
puts "Task retab done"
end
desc 'Remove consecutive blank lines'
task :scrub_gratuitous_newlines do
path = ENV['path'].present? ? ENV['path'] : '.'
sh %{for f in `find #{path} -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i '/./,/^$/!d' $f;
done}, {:verbose => false}
puts "Task scrub_gratuitous_newlines done"
end
desc 'Execute all WHITESPACE tasks'
task :all do
Rake::Task['whitespace:cleanup'].execute
Rake::Task['whitespace:retab'].execute
Rake::Task['whitespace:scrub_gratuitous_newlines'].execute
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment