lib/reality/zapwhite.rb in zapwhite-2.12.0 vs lib/reality/zapwhite.rb in zapwhite-2.13.0
- old
+ new
@@ -78,12 +78,12 @@
content = File.read(full_filename, :encoding => "bom|#{encoding}")
content =
config[:dos] ?
- clean_dos_whitespace(filename, content, config[:eofnl]) :
- clean_whitespace(filename, content, config[:eofnl])
+ clean_dos_whitespace(filename, content, config[:eofnl], config[:allow_empty]) :
+ clean_whitespace(filename, content, config[:eofnl], config[:allow_empty])
if config[:nodupnl]
while content.gsub!(/\n\n\n/, "\n\n")
# Keep removing duplicate new lines till they have gone
end
end
@@ -134,10 +134,11 @@
attr = @attributes.attributes(f)
if attr['text']
files[f] = {
:dos => (attr['eol'] == 'crlf'),
:encoding => attr['encoding'],
+ :allow_empty => attr['allow_empty'].nil? ? false : !!attr['allow_empty'],
:nodupnl => attr['dupnl'].nil? ? false : !attr['dupnl'],
:eofnl => attr['eofnl'].nil? ? true : !!attr['eofnl']
}
end
end
@@ -152,32 +153,34 @@
yield f unless exclude_patterns.any? {|p| p =~ f}
end
end
end
- def clean_whitespace(filename, content, eofnl)
+ def clean_whitespace(filename, content, eofnl, allow_empty)
begin
content.gsub!(/\r\n/, "\n")
content.gsub!(/[ \t]+\n/, "\n")
content.gsub!(/[ \r\t\n]+\Z/, '')
content += "\n" if eofnl
rescue
puts "Skipping whitespace cleanup: #{filename}"
end
+ return '' if allow_empty && content.strip.length == 0
content
end
- def clean_dos_whitespace(filename, content, eofnl)
+ def clean_dos_whitespace(filename, content, eofnl, allow_empty)
begin
content.gsub!(/\r\n/, "\n")
content.gsub!(/[ \t]+\n/, "\n")
content.gsub!(/[ \r\t\n]+\Z/, '')
content += "\n" if eofnl
content.gsub!(/\n/, "\r\n")
rescue
puts "Skipping dos whitespace cleanup: #{filename}"
end
+ return '' if allow_empty && content.strip.length == 0
content
end
# Evaluate block after changing directory to specified directory
def in_dir(dir, &block)
@@ -204,10 +207,11 @@
attributes.text_rule('.node-version')
# Bazel defaults
attributes.text_rule('.bazelrc')
attributes.text_rule('WORKSPACE')
- attributes.text_rule('BUILD')
+ attributes.text_rule('BUILD', :allow_empty => true)
+ attributes.text_rule('BUILD.bazel', :allow_empty => true)
attributes.text_rule('*.bzl')
# Ruby defaults
attributes.text_rule('Gemfile')
attributes.text_rule('*.gemspec')