<commit_before>require 'rubocop'
require 'tempfile'

module HamlLint
  class Linter::RubyScript < Linter
    include LinterRegistry

    def initialize
      super
      @rubocop = Rubocop::CLI.new
    end

    def run(parser)
      @parser = parser
      @extractor = ScriptExtractor.new(parser)
      extracted_code = @extractor.extract
      find_lints(extracted_code)
    end

  private

    def find_lints(code)
      original_filename = "#{File.basename(@parser.filename)}_" if @parser.filename

      Tempfile.open("haml-lint_#{original_filename}extracted_code") do |f|
        f.write(code)
        f.close
        extract_lints_from_offences(lint_file(f.path))
      end
    end<commit_msg>Ensure trailing newline before passing to Rubocop<commit_after>require 'rubocop'
require 'tempfile'

module HamlLint
  class Linter::RubyScript < Linter
    include LinterRegistry

    def initialize
      super
      @rubocop = Rubocop::CLI.new
    end

    def run(parser)
      @parser = parser
      @extractor = ScriptExtractor.new(parser)
      extracted_code = @extractor.extract.strip

      # Ensure a final newline in the code we feed to Rubocop
      find_lints(extracted_code + "\n") unless extracted_code.empty?
    end

  private

    def find_lints(code)
      original_filename = "#{File.basename(@parser.filename)}_" if @parser.filename

      Tempfile.open("haml-lint_#{original_filename}extracted_code") do |f|
        f.write(code)
        f.close
        extract_lints_from_offences(lint_file(f.path))
      end
    end
{'fraction_non_alphanumeric': 0.08836907082521117, 'fraction_numerical': 0.0, 'mean_word_length': 3.041994750656168, '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': '4805251', 'n_tokens_mistral': 503, 'n_tokens_neox': 491, 'n_words': 103}