<commit_before>module Middleman
  module RemoveIndent
    class Extension < ::Middleman::Extension
      option :exts, %w(.html .css), 'List of target file extensions'
      option :remove_blank_line, false, 'Remove Brank Line from target files'

      def initialize(app, options_hash = {}, &block)
        super

        exts = (options.exts.is_a?(String)) ? Array(options.exts) : options.exts
        build_dir = app.build_dir
        extension = self

        app.after_build do
          targets = extension.target_files(build_dir, exts)
          extension.update_file!(targets)
        end
      end

      def target_files(dir, exts)
        paths = []
        exts.each do |ext|
          paths.concat(Dir.glob(dir + "/**/*#{ext}"))
        end
        paths
      end

      def update_file!(target_files)
        target_files.each do |file|
          open(file) do |f|
            data = []
            f.each_line do |line|
              line = remove_indent(line)
              data.push(line)
            end
            File.write(file, data.join)
          end
        end
      end

      def remove_indent(line)
        line.gsub!(/^(\s|\t)+/, '')
        (line.empty? && !options.remove_blank_line) ? "\n" : line
      end
    end
  end
end

<commit_msg>Refactor with Rubucop<commit_after>module Middleman
  module RemoveIndent
    # Middleman Remove Indent Extension
    class Extension < ::Middleman::Extension
      option :exts, %w(.html .css), 'List of target file extensions'
      option :remove_blank_line, false, 'Remove Brank Line from target files'

      def initialize(app, options_hash = {}, &block)
        super
        extension = self
        build_dir = app.build_dir
        exts      = options.exts
        exts      = Array(exts) if exts.instance_of? String

        app.after_build do
          targets = extension.target_files(build_dir, exts)
          extension.update_file!(targets)
        end
      end

      def target_files(dir, exts)
        paths = []
        exts.each do |ext|
          paths.concat(Dir.glob(dir + "/**/*#{ext}"))
        end
        paths
      end

      def update_file!(target_files)
        target_files.each do |file|
          open(file) do |f|
            data = []
            f.each_line do |line|
              line = remove_indent(line)
              data.push(line)
            end
            File.write(file, data.join)
          end
        end
      end

      def remove_indent(line)
        line.gsub!(/^(\s|\t)+/, '')
        (line.empty? && !options.remove_blank_line) ? "\n" : line
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10675883256528418, 'fraction_numerical': 0.0, 'mean_word_length': 1.7831196581196582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7576117', 'n_tokens_mistral': 791, 'n_tokens_neox': 776, 'n_words': 189}