<commit_before>// Operations on rules

var fs = require('fs');
var path = require('path');
var rules; // Cashing list of rules, so that we only load them once

function getAllRules() {
  if (!rules) {
    rules = [];
    fs.readdirSync(path.join(__dirname, 'rules')).forEach(function(file) {
      rules.push(require(path.join(__dirname, 'rules', file)));
    });
  }
  return rules;
}

function getRule(rule) {
  var rules = getAllRules();
  for (var i = 0; i < rules.length; i ++) {
    if (rules[i].name === rule) {
      return rules[i];
    }
  }
}

function doesRuleExist(rule) {
  return getRule(rule) != undefined;
}

function isRuleEnabled(ruleConfig) {
  if (Array.isArray(ruleConfig)) {
    return ruleConfig[0] === 'on';
  }
  return ruleConfig === 'on';
}

function runAllEnabledRules(parsedFile, fileName, configuration) {
  var errors = [];
  var ignoreFutureErrors = false;
  getAllRules().forEach(function(rule) {<commit_msg>use a hash to store and get rules (#53)<commit_after>// Operations on rules

var fs = require('fs');
var path = require('path');
var rules; // Cashing list of rules, so that we only load them once

function getAllRules() {
  if (!rules) {
    rules = {};
    fs.readdirSync(path.join(__dirname, 'rules')).forEach(function(file) {
      var ruleName = file.replace(/\.js$/, '');
      rules[ruleName] = require(path.join(__dirname, 'rules', file));
    });
  }
  return rules;
}

function getRule(rule) {
  return getAllRules()[rule];
}

function doesRuleExist(rule) {
  return getRule(rule) !== undefined;
}

function isRuleEnabled(ruleConfig) {
  if (Array.isArray(ruleConfig)) {
    return ruleConfig[0] === 'on';
  }
  return ruleConfig === 'on';
}

function runAllEnabledRules(parsedFile, fileName, configuration) {
  var errors = [];
  var ignoreFutureErrors = false;
  var rules = getAllRules();
  Object.keys(rules).forEach(function(ruleName) {
    var rule = rules[ruleName];
{'fraction_non_alphanumeric': 0.15636363636363637, 'fraction_numerical': 0.0025974025974025974, 'mean_word_length': 4.002597402597402, 'pattern_counts': {'":': 0, '<': 4, '<?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': '1591206', 'n_tokens_mistral': 620, 'n_tokens_neox': 623, 'n_words': 159}