<commit_before>require 'oj'
require 'pronto'

module Pronto
  class OjValidator < Runner
    def run(patches, _)
      return [] unless patches

      patches.select { |patch| patch.additions > 0 && json_file?(patch.new_file_full_path) }
             .map    { |patch| inspect(patch) }
             .flatten.compact
    end

    def inspect(patch)
      begin
        Oj.load_file(patch.new_file_full_path.to_s)
      rescue Oj::ParseError => e
        match = /^(.* at) line (\d+), (column \d+)/.match(e.message)
        raise unless match
        msg_prefix = match[1]
        line_numbers = [match[2].to_i]
        line_numbers << line_numbers[0] - 1 if msg_prefix.end_with?('not terminated at')
        line = patch.added_lines.detect { |added_line| line_numbers.include?(added_line.new_lineno) }
        return [new_message("#{msg_prefix} #{match[3]}", line)] if line
      end
      []
    end

    def new_message(offence, line)
      path = line.patch.delta.new_file[:path]
      level = :error

      Message.new(path, line, level, offence)
    end

    def json_file?(path)
      File.extname(path) == '.json'
    end
  end
end<commit_msg>British -> American spelling<commit_after>require 'oj'
require 'pronto'

module Pronto
  class OjValidator < Runner
    def run(patches, _)
      return [] unless patches

      patches.select { |patch| patch.additions > 0 && json_file?(patch.new_file_full_path) }
             .map    { |patch| inspect(patch) }
             .flatten.compact
    end

    def inspect(patch)
      begin
        Oj.load_file(patch.new_file_full_path.to_s)
      rescue Oj::ParseError => e
        match = /^(.* at) line (\d+), (column \d+)/.match(e.message)
        raise unless match
        msg_prefix = match[1]
        line_numbers = [match[2].to_i]
        line_numbers << line_numbers[0] - 1 if msg_prefix.end_with?('not terminated at')
        line = patch.added_lines.detect { |added_line| line_numbers.include?(added_line.new_lineno) }
        return [new_message("#{msg_prefix} #{match[3]}", line)] if line
      end
      []
    end

    def new_message(offense, line)
      path = line.patch.delta.new_file[:path]
      level = :error

      Message.new(path, line, level, offense)
    end

    def json_file?(path)
      File.extname(path) == '.json'
    end
  end
end
{'fraction_non_alphanumeric': 0.12624297449200172, 'fraction_numerical': 0.005188067444876783, 'mean_word_length': 2.5007564296520424, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, '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': '2943224', 'n_tokens_mistral': 792, 'n_tokens_neox': 767, 'n_words': 165}