<commit_before>'use strict';

var fs = require('fs');
var path = require('path');
var XRegExp = require('xregexp').XRegExp;
var GoogleAnalytics = require('./google-analytics');
var EventEmitter = require('events').EventEmitter;
var util = require('util');

module.exports = (function () {

  function ErrorMatcher() {
    this.regex = null;
    this.cwd = null;
    this.stdout = null;
    this.stderr = null;
    this.currentMatch = [];

    atom.commands.add('atom-workspace', 'build:error-match', this.match.bind(this));
    atom.commands.add('atom-workspace', 'build:error-match-first', this.matchFirst.bind(this));
  }

  util.inherits(ErrorMatcher, EventEmitter);

  ErrorMatcher.prototype._goto = function () {
    if (this.currentMatch[0].absFile) {
      atom.notifications.addWarning('`absFile` is deprecated.', {
        detail: 'You should name your match `file` only. It handles both relative and absolute paths.'
      });
    }

    if (!this.currentMatch[0].file && !this.currentMatch[0].absFile) {
      return this.emit('error', 'Did not match any file. Don\'t know what to open.');
    }

      var match = this.currentMatch[0];
    var file = match.file ? match.file : match.absFile;
    if (!path.isAbsolute(file)) {
      file = this.cwd + path.sep + file;
    }

    var row = match.line ? match.line - 1 : 0; /* Because atom is zero-based */
    var col =  match.col ? match.col - 1 : 0; /* Because atom is zero-based */

    this.currentMatch.push(this.currentMatch.shift());

    fs.exists(file, function (exists) {
      if (!exists) {
        return this.emit('error', 'Matched file does not exist: ' + file);
      }
      atom.workspace.open(file, {
        initialLine: row,
        initialColumn: col,
        searchAllPanes: true
      });
      this.emit('scroll', match.type, match.id);
    }.bind(this));
  };

  ErrorMatcher.prototype._parse = function () {
    this.currentMatch = XRegExp.forEach(this.output, this.regex, function (match, i) {
      match.type = 'error';
      match.id = i;
      this.push(match);
    }, []);
    var output = this.output;
    var matchIndex;
    for (matchIndex in this.currentMatch) {
      var search = this.currentMatch[matchIndex][0];
      var replace = '<b class=\"' + this.currentMatch[matchIndex].type + '\" id=\"' + this.currentMatch[matchIndex].id + '\">$&</b>';
      output = XRegExp.replace(output, search, replace, 'one');
    }
    this.emit('replace', output);
    return this.currentMatch.length;
  };

  ErrorMatcher.prototype.set = function (regex, cwd, output) {<commit_msg>fixed reinserting errors with < ><commit_after>'use strict';

var fs = require('fs');
var path = require('path');
var XRegExp = require('xregexp').XRegExp;
var GoogleAnalytics = require('./google-analytics');
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var _ = require('lodash');

module.exports = (function () {

  function ErrorMatcher() {
    this.regex = null;
    this.cwd = null;
    this.stdout = null;
    this.stderr = null;
    this.currentMatch = [];

    atom.commands.add('atom-workspace', 'build:error-match', this.match.bind(this));
    atom.commands.add('atom-workspace', 'build:error-match-first', this.matchFirst.bind(this));
  }

  util.inherits(ErrorMatcher, EventEmitter);

  ErrorMatcher.prototype._goto = function () {
    var match = this.currentMatch[0];
    if (match.absFile) {
      atom.notifications.addWarning('`absFile` is deprecated.', {
        detail: 'You should name your match `file` only. It handles both relative and absolute paths.'
      });
    }

    if (!match.file && !match.absFile) {
      return this.emit('error', 'Did not match any file. Don\'t know what to open.');
    }

    var file = match.file ? match.file : match.absFile;
    if (!path.isAbsolute(file)) {
      file = this.cwd + path.sep + file;
    }

    var row = match.line ? match.line - 1 : 0; /* Because atom is zero-based */
    var col =  match.col ? match.col - 1 : 0; /* Because atom is zero-based */

    this.currentMatch.push(this.currentMatch.shift());

    fs.exists(file, function (exists) {
      if (!exists) {
        return this.emit('error', 'Matched file does not exist: ' + file);
      }
      atom.workspace.open(file, {
        initialLine: row,
        initialColumn: col,
        searchAllPanes: true
      });
      this.emit('scroll', match.type, match.id);
    }.bind(this));
  };

  ErrorMatcher.prototype._parse = function () {
    this.currentMatch = XRegExp.forEach(this.output, this.regex, function (match, i) {
      match.type = 'error';
      match.id = i;
      this.push(match);
    }, []);
    var output = this.output;
    var matchIndex;
    for (matchIndex in this.currentMatch) {
      var search = this.currentMatch[matchIndex][0];
      var replace = '<b class=\"' + this.currentMatch[matchIndex].type + '\" id=\"' + this.currentMatch[matchIndex].id + '\">' + _.escape(search) + '</b>';
      output = output.replace(search, replace);
    }
    this.emit('replace', output);
    return this.currentMatch.length;
  };

  ErrorMatcher.prototype.set = function (regex, cwd, output) {
{'fraction_non_alphanumeric': 0.15947102294826915, 'fraction_numerical': 0.0029171528588098016, 'mean_word_length': 3.01796875, 'pattern_counts': {'":': 0, '<': 8, '<?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': '1507970', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1590, 'n_words': 373}