code: function prepareRules(options, rules, defaultDir) {
    rules = u.findRules(options, rules, defaultDir);
    var anyStartRules = [];
    var anyEndRules = [];
    var typeToRules = {'': anyStartRules, 'end': anyEndRules};
  
    rules.forEach(function (rule) {
      var ruleTypes = rule.type || [];
      ruleTypes = Array.isArray(ruleTypes) ? ruleTypes : [ruleTypes];
      if (ruleTypes.length === 0) {
        ruleTypes.push('');
      }
      ruleTypes.forEach(function (ruleType) {
        if (ruleType === '') {
          anyStartRules.push(rule);
          // add this any rule to the end of any typed start rule lists
          Object.keys(typeToRules).forEach(function (key) {
            if (key !== '' && key !== 'end' && key.substring(0,4) !== 'end-') {
              typeToRules[key].push(rule);
            }
          });
        } else if (ruleType === 'end') {
          anyEndRules.push(rule);
          // add this any rule to the end of any typed end rule lists
          Object.keys(typeToRules).forEach(function (key) {
            if (key !== '' && key.substring(0,4) === 'end-') {
              typeToRules[key].push(rule);
            }
          });
        } else {
          if (!(ruleType in typeToRules)) {
            typeToRules[ruleType] = [];
            if (ruleType.substring(0,4) !== 'end-') {
              // put all preceding any start rules first
              typeToRules[ruleType] = [].concat(anyStartRules);
            } else {
              // put all preceding any end rules first
              typeToRules[ruleType] = [].concat(anyEndRules);
            }
          }
          typeToRules[ruleType].push(rule);
        }
      });
    });
  
    return typeToRules;
  }
docs: /*
  Prepare rules from one or more rules files so they fire correctly.
  @param {Array|String} rules One or more names of rules modules.
  @param {String} defaultDir Default location for rules modules.