# frozen_string_literal: true

module Lintress
  class MagicCommentResolution < Lintress::Resolution
    def transform
      tmp_file = Dir.pwd + '/tmp.txt'
      offender = Dir.pwd + '/' + @offense.ofile
      # prepend "# frozen_string_literal: true\n\n" to file
      magic_comment = "# frozen_string_literal: true\n\n"

      # write out the file
      File.open tmp_file, 'w' do |f|
        f << magic_comment
        f << File.read(offender)
      end

      File.rename tmp_file, offender
    end
  end
end
