Skip to content

Commit

Permalink
Squash just literal spaces, not any whitespace. Using ruby again.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewtodd committed Oct 6, 2008
1 parent e8055bd commit 98860f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/git-whitespace
Expand Up @@ -3,4 +3,4 @@
require File.join(File.dirname(__FILE__), '..', 'lib', 'whitespace')

files = Finder.new.files(Dir.pwd)
exec 'perl', '-pi', '-e', 's/^\s+$//g', *files
exec "ruby", "-pi", "-e", "gsub(/^ +$/, '')", *files
12 changes: 6 additions & 6 deletions lib/whitespace.rb
Expand Up @@ -5,27 +5,27 @@ def initialize
@directories_to_prune = %w[.git vendor]
@extensions = %w[builder css erb haml html icalendar js rake rb yml] + ['']
end

def files(directory)
files = []

Find.find directory do |path|
if FileTest.directory? path
Find.prune if should_prune?(path)
else
files.push(path) if should_include?(path)
end
end

files
end

private

def should_include?(path)
@extensions.include?(File.extname(path).sub(/^\./, ''))
end

def should_prune?(path)
@directories_to_prune.include?(File.basename(path))
end
Expand Down
8 changes: 4 additions & 4 deletions test/unit/whitespace_test.rb
Expand Up @@ -3,19 +3,19 @@
class WhitespaceTest < Test::Unit::TestCase
context Finder do
setup { @files = Finder.new.files(fixtures) }

should 'ignore vendor' do
assert_does_not_contain @files, /vendor/
end

should 'ignore .extension' do
assert_does_not_contain @files, fixtures('lib', 'file_with_unusual.extension')
end

should 'include fixtures.rb' do
assert_contains @files, fixtures('lib', 'fixtures.rb')
end

should 'include README' do
assert_contains @files, fixtures('README')
end
Expand Down

0 comments on commit 98860f0

Please sign in to comment.