<commit_before>'use strict';
var _ = require('lodash');
var Promise = require('bluebird');

const customResourceTypeRegex = /^Custom::.*/;
const requiredPropertyRegex = /Required: Yes/i;

// Creates an object (keyed by resource name) of properties that are required.
var getRequiredProperties = function (resources) {
  var requiredProperties = {};
  _.each(resources, function (r) {
    requiredProperties[r.type] = [];
    _.each(r.properties, function (p, i) {
      var description = r.descriptions[i];
      if (requiredPropertyRegex.test(description)) {
        requiredProperties[r.type].push(p);
      }
    });
  });

  return Promise.resolve(requiredProperties);
};

var checkTypes = function (template) {
  return new Promise(function (resolve) {
    var resources = require('../../data/resources.json');
    var resourceTypes = _.map(resources, 'type');
    var errors = _(template.Resources)
      .map(function (r, name) {
        if (!r.Type.match(customResourceTypeRegex) &&
            (_.indexOf(resourceTypes, r.Type) < 0)) {
          return `${r.Type} is not a valid type for ${name}`;
        }
      })<commit_msg>Refactor getRequiredProperties promise setup.<commit_after>'use strict';
var _ = require('lodash');
var Promise = require('bluebird');

const customResourceTypeRegex = /^Custom::.*/;
const requiredPropertyRegex = /Required: Yes/i;

// Creates an object (keyed by resource name) of properties that are required.
var getRequiredProperties = function (resources) {
  return new Promise(function (resolve) {
    var requiredProperties = {};
    _.each(resources, function (r) {
      requiredProperties[r.type] = [];
      _.each(r.properties, function (p, i) {
        var description = r.descriptions[i];
        if (requiredPropertyRegex.test(description)) {
          requiredProperties[r.type].push(p);
        }
      });
    });
    resolve(requiredProperties);
  });
};

var checkTypes = function (template) {
  return new Promise(function (resolve) {
    var resources = require('../../data/resources.json');
    var resourceTypes = _.map(resources, 'type');
    var errors = _(template.Resources)
      .map(function (r, name) {
        if (!r.Type.match(customResourceTypeRegex) &&
            (_.indexOf(resourceTypes, r.Type) < 0)) {
          return `${r.Type} is not a valid type for ${name}`;
        }
      })
{'fraction_non_alphanumeric': 0.14533898305084747, 'fraction_numerical': 0.000847457627118644, 'mean_word_length': 3.2464028776978417, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6474209', 'n_tokens_mistral': 665, 'n_tokens_neox': 663, 'n_words': 172}