<commit_before>var astUtil = require("./util/ast");
var errorUtil = require("./util/error");

var ELEMENTS = {
  FOR: "For"
};
var ATTRIBUTES = {
  EACH: "each",
  OF: "of",
  INDEX: "index",
  BODY: "body"
};

function addMapParam(types, params, attributes, attributeKey) {
  var attribute = attributes[attributeKey];
  if (attribute && attribute.value) {
    params.push(types.Identifier(attribute.value.value));
  } else {
    params.push(types.Identifier(attributeKey));
  }
}

function checkForString(attributes, name, errorInfos) {
  if (attributes[name] && !astUtil.isStringLiteral(attributes[name])) {
    errorUtil.throwNotStringType(name, errorInfos);
  }
}

function checkForExpression(attributes, name, errorInfos) {
  if (attributes[name] && !astUtil.isExpressionContainer(attributes[name])) {
    errorUtil.throwNotExpressionType(name, errorInfos);
  }
}

module.exports = function(babel) {
  var types = babel.types;

  return function(node, file) {
    var mapParams = [];
    var errorInfos = { node: node, file: file, element: ELEMENTS.FOR };
    var attributes = astUtil.getAttributeMap(node);
    var children = astUtil.getChildren(types, node);
    var returnExpression = astUtil.getSanitizedExpressionForContent(
      types,
      children
    );

    // required attribute
    if (!attributes[ATTRIBUTES.OF]) {
      errorUtil.throwNoAttribute(ATTRIBUTES.OF, errorInfos);
    }

    if (attributes[ATTRIBUTES.BODY]) {
      return types.callExpression(
        types.memberExpression(
          attributes[ATTRIBUTES.OF].value.expression,
          types.identifier("map")
        ),
        [attributes[ATTRIBUTES.BODY].value.expression, types.identifier("this")]
      );
    } else {
      // check for correct data types, as far as possible
      checkForExpression(attributes, ATTRIBUTES.OF, errorInfos);
      checkForString(attributes, ATTRIBUTES.EACH, errorInfos);
      checkForString(attributes, ATTRIBUTES.INDEX, errorInfos);

      // simply return without any child nodes
      if (!children.length) {
        return returnExpression;
      }

      addMapParam(types, mapParams, attributes, ATTRIBUTES.EACH);
      addMapParam(types, mapParams, attributes, ATTRIBUTES.INDEX);
    }

    return types.callExpression(
      types.memberExpression(
        attributes[ATTRIBUTES.OF].value.expression,
        types.identifier("map")
      ),
      [
        types.functionExpression(
          null,<commit_msg>Fixed lint errors<commit_after>var astUtil = require("./util/ast");
var errorUtil = require("./util/error");

var ELEMENTS = {
  FOR: "For"
};
var ATTRIBUTES = {
  EACH: "each",
  OF: "of",
  INDEX: "index",
  BODY: "body"
};

function addMapParam(types, params, attributes, attributeKey) {
  var attribute = attributes[attributeKey];
  if (attribute && attribute.value) {
    params.push(types.Identifier(attribute.value.value));
  }
  else {
    params.push(types.Identifier(attributeKey));
  }
}

function checkForString(attributes, name, errorInfos) {
  if (attributes[name] && !astUtil.isStringLiteral(attributes[name])) {
    errorUtil.throwNotStringType(name, errorInfos);
  }
}

function checkForExpression(attributes, name, errorInfos) {
  if (attributes[name] && !astUtil.isExpressionContainer(attributes[name])) {
    errorUtil.throwNotExpressionType(name, errorInfos);
  }
}

module.exports = function(babel) {
  var types = babel.types;

  return function(node, file) {
    var mapParams = [];
    var errorInfos = { node: node, file: file, element: ELEMENTS.FOR };
    var attributes = astUtil.getAttributeMap(node);
    var children = astUtil.getChildren(types, node);
    var returnExpression = astUtil.getSanitizedExpressionForContent(
      types,
      children
    );

    // required attribute
    if (!attributes[ATTRIBUTES.OF]) {
      errorUtil.throwNoAttribute(ATTRIBUTES.OF, errorInfos);
    }

    if (attributes[ATTRIBUTES.BODY]) {
      return types.callExpression(
        types.memberExpression(
          attributes[ATTRIBUTES.OF].value.expression,
          types.identifier("map")
        ),
        [attributes[ATTRIBUTES.BODY].value.expression, types.identifier("this")]
      );
    }
    // check for correct data types, as far as possible
    checkForExpression(attributes, ATTRIBUTES.OF, errorInfos);
    checkForString(attributes, ATTRIBUTES.EACH, errorInfos);
    checkForString(attributes, ATTRIBUTES.INDEX, errorInfos);

    // simply return without any child nodes
    if (!children.length) {
      return returnExpression;
    }

    addMapParam(types, mapParams, attributes, ATTRIBUTES.EACH);
    addMapParam(types, mapParams, attributes, ATTRIBUTES.INDEX);

    return types.callExpression(
      types.memberExpression(
        attributes[ATTRIBUTES.OF].value.expression,
        types.identifier("map")
      ),
      [
        types.functionExpression(
          null,
{'fraction_non_alphanumeric': 0.12209660842754368, 'fraction_numerical': 0.0, 'mean_word_length': 3.5391791044776117, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2806092', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1442, 'n_words': 282}