<commit_before>'use strict';

var _ = require("lodash");
var cfg = require('./config');

// if someone tries to call 'require("approvals")...' without calling ".mocha(...) or .
// jasmine(...) they won't get a helpful error. So we put this in there - just in case"
if (typeof beforeEach === "function"){
  beforeEach(function(){
    this.verify = function(){
      throw "You must call either .mocha(__dirname) or .jasmine(__dirname)";
    };
  });
}

var listOfApprovedFiles = {};

process.on("approvalFileApproved", function(fileName){
  listOfApprovedFiles[fileName] = true;
});

process.on('exit', function() {
  var options = cfg.currentConfig();

  if (options.errorOnStaleApprovedFiles) {
    var path = require('path');
    var glob = require('glob');

    var staleApprovals = [];

    listOfApprovedFiles = Object.keys(listOfApprovedFiles).map(function(file){
      return file.replace(/\\/g, "/");
    });

    Array.prototype.unique = function() {
      var o = {}, i, l = this.length, r = [];
      for (i = 0; i < l; i += 1) {
        o[this[i]] = this[i];
      }
      for (i in o) {
        r.push(o[i]);
      }
      return r;
    };

    var flatten = Function.prototype.apply.bind(Array.prototype.concat, []);

    Array.prototype.selectMany = function (fn) {
      return flatten(this.map(fn));
    };

    staleApprovals = listOfApprovedFiles
      .map(function(file){ return path.dirname(file); }) // get just the directory of each approved file.
      .unique() // hmm only unique directories
      .map(function(folder){
        return glob.sync(folder + "**/*.approved.*").filter(function(file){
          return !listOfApprovedFiles[file];
        });
      }) // use 'glob' to find all .approved.* files for each folder.
      .selectMany(function(files){
        return files;
      }) // turn the array of array's into a single array of strings.
      .filter(function(file){
        if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
          return !options.shouldIgnoreStaleApprovedFile(file);
        }
        return true;
      })
      .filter(function(item){
        return listOfApprovedFiles.indexOf(item) < 0;
      }); // only pull the ones that aren't already in the 'listOfApprovedFiles'<commit_msg>The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.<commit_after>'use strict';

var _ = require("lodash");
var cfg = require('./config');

// if someone tries to call 'require("approvals")...' without calling ".mocha(...) or .
// jasmine(...) they won't get a helpful error. So we put this in there - just in case"
if (typeof beforeEach === "function"){
  beforeEach(function(){
    this.verify = function(){
      throw "You must call either .mocha(__dirname) or .jasmine(__dirname)";
    };
  });
}

var listOfApprovedFiles = {};

process.on("approvalFileApproved", function(fileName){
  listOfApprovedFiles[fileName] = true;
});

process.on('exit', function() {
  var options = cfg.currentConfig();

  if (options.errorOnStaleApprovedFiles) {
    var path = require('path');
    var glob = require('glob');

    var staleApprovals = [];

    listOfApprovedFiles = Object.keys(listOfApprovedFiles).map(function(file){
      return file.replace(/\\/g, "/");
    });

    Array.prototype.unique = function() {
      var o = {}, i, l = this.length, r = [];
      for (i = 0; i < l; i += 1) {
        o[this[i]] = this[i];
      }
      for (i in o) {
        if (o.hasOwnProperty(i)) {
          r.push(o[i]);
        }
      }
      return r;
    };

    var flatten = Function.prototype.apply.bind(Array.prototype.concat, []);

    Array.prototype.selectMany = function (fn) {
      return flatten(this.map(fn));
    };

    staleApprovals = listOfApprovedFiles
      .map(function(file){ return path.dirname(file); }) // get just the directory of each approved file.
      .unique() // hmm only unique directories
      .map(function(folder){
        return glob.sync(folder + "**/*.approved.*").filter(function(file){
          return !listOfApprovedFiles[file];
        });
      }) // use 'glob' to find all .approved.* files for each folder.
      .selectMany(function(files){
        return files;
      }) // turn the array of array's into a single array of strings.
      .filter(function(file){
        if (typeof options.shouldIgnoreStaleApprovedFile === "function") {
          return !options.shouldIgnoreStaleApprovedFile(file);
        }
        return true;
      })
      .filter(function(item){
        return listOfApprovedFiles.indexOf(item) < 0;
      }); // only pull the ones that aren't already in the 'listOfApprovedFiles'
{'fraction_non_alphanumeric': 0.15005359056806003, 'fraction_numerical': 0.0012861736334405145, 'mean_word_length': 2.781199351701783, 'pattern_counts': {'":': 0, '<': 7, '<?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': '60724', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1371, 'n_words': 372}