Created
September 14, 2012 10:45
-
-
Save wynst/3721256 to your computer and use it in GitHub Desktop.
rake task to cleanup codebase from devilish whitespace (taken from diaspora project)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rake task to cleanup codebase from devilish whitespace | |
# works on OSX, on linux the :new_line_at_eof task should be `sed '$a\'` | |
# | |
# at the end of the day, 'cleanup whitespace' commit that cleans up all the whitespace | |
# wouldn't worth to be included in the repo. this is because | |
# `git blame` will fail with many 'cleanup whitespace' commits | |
# | |
# ref: | |
# https://www.chiliproject.org/issues/436 | |
# https://github.com/diaspora/diaspora/commits/master/lib/tasks/whitespace.rake | |
namespace :whitespace do | |
desc 'Removes trailing whitespace' | |
task :cleanup do | |
sh %{for f in `find . -type f | grep -v -e '.git/' -e 'tmp/' -e 'app/assets/images' -e 'public/' -e 'db/' -e 'doc/'`; | |
do cat $f | sed 's/[ \t]*$//' > tempo; cp tempo $f; rm tempo; echo -n .; | |
done} | |
end | |
desc 'Converts hard-tabs into two-space soft-tabs' | |
task :retab do | |
sh %{for f in `find . -type f | grep -v -e '.git/' -e 'tmp/' -e 'app/assets/images' -e 'public/' -e 'db/' -e 'doc/'`; | |
do cat $f | sed 's/\t/ /g' > tempo; cp tempo $f; rm tempo; echo -n .; | |
done} | |
end | |
desc 'Remove consecutive blank lines' | |
task :scrub_gratuitous_newlines do | |
sh %{for f in `find . -type f | grep -v -e '.git/' -e 'tmp/' -e 'app/assets/images' -e 'public/' -e 'db/' -e 'doc/'`; | |
do cat $f | sed '/./,/^$/!d' > tempo; cp tempo $f; rm tempo; echo -n .; | |
done} | |
end | |
desc 'Add new line at the end of the file' | |
task :new_line_at_eof do | |
sh %{for f in `find . -type f | grep -v -e '.git/' -e 'tmp/' -e 'app/assets/images' -e 'public/' -e 'db/' -e 'doc/'`; | |
do cat $f | sed '$a\\' > tempo; cp tempo $f; rm tempo; echo -n .; | |
done} | |
end | |
task :all => [:new_line_at_eof, :cleanup, :retab, :scrub_gratuitous_newlines] do | |
desc "clean whitespace" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment