class Lintress::MagicCommentResolution

Public Instance Methods

transform() click to toggle source
# File lib/lintress/magic_comment_resolution.rb, line 5
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