def run
      normalize_count = 0

      if generate_gitattributes?
        output_options = {:prefix => '# DO NOT EDIT: File is auto-generated', :normalize => true}
        new_gitattributes = generate_gitattributes!
        new_content = new_gitattributes.as_file_contents(output_options)
        old_content = File.exist?(@attributes.attributes_file) ? IO.read(@attributes.attributes_file) : nil
        if new_content != old_content
          @attributes = new_gitattributes
          if check_only?
            puts 'Non-normalized .gitattributes file'
          else
            puts 'Fixing: .gitattributes'
            @attributes.write(output_options)
          end
          normalize_count += 1
        end
      end

      files = {}

      collect_file_attributes(files)

      files.each_pair do |filename, config|
        full_filename = "#{@base_directory}/#{filename}"
        original_bin_content = File.binread(full_filename)

        encoding = config[:encoding].nil? ? 'utf-8' : config[:encoding].gsub(/^UTF/,'utf-')

        content = File.read(full_filename, :encoding => "bom|#{encoding}")

        content =
          config[:dos] ?
            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
        if content.bytes != original_bin_content.bytes
          normalize_count += 1
          if check_only?
            puts "Non-normalized whitespace in #{filename}"
          else
            puts "Fixing: #{filename}"
            File.open(full_filename, 'wb') do |out|
              out.write content
            end
          end
        end
      end

      normalize_count
    end
def run
      normalize_count = 0

      if generate_gitattributes?
        output_options = {:prefix => '# DO NOT EDIT: File is auto-generated', :normalize => true}
        new_gitattributes = generate_gitattributes!
        new_content = new_gitattributes.as_file_contents(output_options)
        old_content = File.exist?(@attributes.attributes_file) ? IO.read(@attributes.attributes_file) : nil
        if new_content != old_content
          @attributes = new_gitattributes
          if check_only?
            puts 'Non-normalized .gitattributes file'
          else
            puts 'Fixing: .gitattributes'
            @attributes.write(output_options)
          end
          normalize_count += 1
        end
      end

      files = {}

      collect_file_attributes(files)

      files.each_pair do |filename, config|
        full_filename = "#{@base_directory}/#{filename}"
        original_bin_content = File.binread(full_filename)

        encoding = config[:encoding].nil? ? 'utf-8' : config[:encoding].gsub(/^UTF/,'utf-')

        content = File.read(full_filename, :encoding => "bom|#{encoding}")

        content =
          config[:dos] ?
            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
        if content.bytes != original_bin_content.bytes
          normalize_count += 1
          if check_only?
            puts "Non-normalized whitespace in #{filename}"
          else
            puts "Fixing: #{filename}"
            File.open(full_filename, 'wb') do |out|
              out.write content
            end
          end
        end
      end

      normalize_count
    end
Run normalization process across directory.
 Return the number of files that need normalization