<commit_before>var AWS = require('./core');
var inherit = AWS.util.inherit;
var xml2js = require('xml2js');

AWS.XMLParser = inherit({

  constructor: function XMLParser(rules) {
    this.rules = rules;
  },

  // options passed to xml2js parser
  options: {
    explicitCharkey: false, // undocumented
    trim: false,            // trim the leading/trailing whitespace from text nodes
    normalize: false,       // trim interior whitespace inside text nodes
    explicitRoot: false,    // return the root node in the resulting object?
    emptyTag: {},           // the default value for empty nodes
    explicitArray: true,    // always put child nodes in an array
    ignoreAttrs: false,     // ignore attributes, only create text nodes
    mergeAttrs: true,       // merge attributes and child elements
    validator: null         // a callable validator
  },

  // Call this method with an xml string to parse.  The callback will be
  // called with the parsed javascript structure.  Throws an error if the 
  // XML can not be parsed.
  parse: function parse(xml, callback) {
    var that = this;
    var parser = new xml2js.Parser(this.options);
    parser.parseString(xml, function (error, doc) {
      if (error)
        throw { code: 'AWS.XMLParser.Error', message: error.message };
      else
        callback.call(this, that.parseStructure(doc, that.rules));
    });
  },

  parseStructure: function parseStructure(structure, rules) {
    var that = this;
    var data = {};
    AWS.util.each(structure, function (memberName, value) {
      data[memberName] = that.parseMember(value[0], rules[memberName] || {});
    });
    return data;
  },

  parseList: function parseList(list, rules) {
    var data = [];
    AWS.util.arrayEach.call(this, list, function(member) {
      data.push(this.parseMember(member, rules));
    });
    return data;
  },

  parseMember: function parseMember(member, rules) {

    if (!rules.t) rules.t = typeof member === 'string' ? 's' : 'o';

    if (rules.t === 's') {

      return member;

    } else if (rules.t === 'o') {

      return this.parseStructure(member, rules.m || {});

    } else if (rules.t === 'a') {

      var memberRules = rules.m || {};
      var memberName = memberRules.n || 'member';
      return this.parseList(member[memberName], rules.m || {});

    } else {

      msg = 'unhandled type: ' + rules.t;
      throw { code: 'AWS.XMLParser.Error', message: msg };

    }
  }

});<commit_msg>Fixed a few linting errors.<commit_after>var AWS = require('./core');
var inherit = AWS.util.inherit;
var xml2js = require('xml2js');

AWS.XMLParser = inherit({

  constructor: function XMLParser(rules) {
    this.rules = rules;
  },

  // options passed to xml2js parser
  options: {
    explicitCharkey: false, // undocumented
    trim: false,            // trim the leading/trailing whitespace from text nodes
    normalize: false,       // trim interior whitespace inside text nodes
    explicitRoot: false,    // return the root node in the resulting object?
    emptyTag: {},           // the default value for empty nodes
    explicitArray: true,    // always put child nodes in an array
    ignoreAttrs: false,     // ignore attributes, only create text nodes
    mergeAttrs: true,       // merge attributes and child elements
    validator: null         // a callable validator
  },

  // Call this method with an xml string to parse.  The callback will be
  // called with the parsed javascript structure.  Throws an error if the
  // XML can not be parsed.
  parse: function parse(xml, callback) {
    var that = this;
    var parser = new xml2js.Parser(this.options);
    parser.parseString(xml, function (error, doc) {
      if (error)
        throw { code: 'AWS.XMLParser.Error', message: error.message };
      else
        callback.call(this, that.parseStructure(doc, that.rules));
    });
  },

  parseStructure: function parseStructure(structure, rules) {
    var that = this;
    var data = {};
    AWS.util.each(structure, function (memberName, value) {
      data[memberName] = that.parseMember(value[0], rules[memberName] || {});
    });
    return data;
  },

  parseList: function parseList(list, rules) {
    var data = [];
    AWS.util.arrayEach.call(this, list, function (member) {
      data.push(this.parseMember(member, rules));
    });
    return data;
  },

  parseMember: function parseMember(member, rules) {

    if (!rules.t) rules.t = typeof member === 'string' ? 's' : 'o';

    if (rules.t === 's') {

      return member;

    } else if (rules.t === 'o') {

      return this.parseStructure(member, rules.m || {});

    } else if (rules.t === 'a') {

      var memberRules = rules.m || {};
      var memberName = memberRules.n || 'member';
      return this.parseList(member[memberName], rules.m || {});

    } else {

      var msg = 'unhandled type: ' + rules.t;
      throw { code: 'AWS.XMLParser.Error', message: msg };

    }
  }

});
{'fraction_non_alphanumeric': 0.13097165991902834, 'fraction_numerical': 0.0020242914979757085, 'mean_word_length': 2.6736059479553904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '6371240', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1449, 'n_words': 450}