<commit_before>require 'autotest'

class RspecCommandError < StandardError; end

class Autotest::NodeRspec < Autotest

  NODE_MODULES = File.expand_path('../../node_modules', __FILE__)
  NODELINT = File.join(NODE_MODULES, '.bin/nodelint')
  JASMINE = File.join(NODE_MODULES, '.bin/jasmine-node')

  def initialize
    super
    self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n\n?(.*?(\n\n\(.*?)?)\n\n/m
    self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
    patch_jslint
  end

  # Patches jslint to allow "foo.should.exist;"
  def patch_jslint
    patch_file = File.expand_path('../jslint.js.patch', __FILE__)
    Dir.chdir(File.join(NODE_MODULES, 'nodelint/jslint')) do
      if File.read('jslint.js') !~ /shouldMethods/
        cmd = "patch < #{patch_file}"
        if system(cmd)
          puts "patched jslint.js"
        else
          $stderr.puts "#{cmd} failed"
        end
      end
    end
  end

  def consolidate_failures(failed)
    filters = new_hash_of_arrays
    failed.each do |spec, trace|
      if trace =~ /\n(\.\/)?(.*spec\.rb):[\d]+:/
        filters[$2] << spec
      end
    end
    return filters
  end

  def make_test_cmd(files_to_test)
    files_to_test.empty? ? '' :
<<<<<<< HEAD
      "#{NODELINT} *.js lib/*.js lib/mechanize/*.js spec/*.js " +
      "--config nodelint_config.js && " +
=======
      "#{NODELINT} *.js lib/*.js lib/*/*.js lib/*/*/*.js spec/*.js --config nodelint_config.js && " +
>>>>>>> ffb2806a836b58120c244a3edeee2aab6930f37d
      "#{JASMINE} --noColor spec " +
      add_options_if_present + redirect
  end

  def redirect
    ' 2> /dev/null'
  end<commit_msg>fix merge typo<commit_after>require 'autotest'

class RspecCommandError < StandardError; end

class Autotest::NodeRspec < Autotest

  NODE_MODULES = File.expand_path('../../node_modules', __FILE__)
  NODELINT = File.join(NODE_MODULES, '.bin/nodelint')
  JASMINE = File.join(NODE_MODULES, '.bin/jasmine-node')

  def initialize
    super
    self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n\n?(.*?(\n\n\(.*?)?)\n\n/m
    self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
    patch_jslint
  end

  # Patches jslint to allow "foo.should.exist;"
  def patch_jslint
    patch_file = File.expand_path('../jslint.js.patch', __FILE__)
    Dir.chdir(File.join(NODE_MODULES, 'nodelint/jslint')) do
      if File.read('jslint.js') !~ /shouldMethods/
        cmd = "patch < #{patch_file}"
        if system(cmd)
          puts "patched jslint.js"
        else
          $stderr.puts "#{cmd} failed"
        end
      end
    end
  end

  def consolidate_failures(failed)
    filters = new_hash_of_arrays
    failed.each do |spec, trace|
      if trace =~ /\n(\.\/)?(.*spec\.rb):[\d]+:/
        filters[$2] << spec
      end
    end
    return filters
  end

  def make_test_cmd(files_to_test)
    files_to_test.empty? ? '' :
      "#{NODELINT} *.js lib/*.js lib/mechanize/*.js spec/*.js " +
      "--config nodelint_config.js && " +
      "#{JASMINE} --noColor spec " +
      add_options_if_present + redirect
  end

  def redirect
    ' 2> /dev/null'
  end
{'fraction_non_alphanumeric': 0.18930041152263374, 'fraction_numerical': 0.008547008547008548, 'mean_word_length': 2.648960739030023, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 12, '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': '5793729', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1225, 'n_words': 213}