<commit_before>'use strict';

var _ = require('lodash')
    , util = require('util');

function AWSResource(type, propdefinitions, name, properties, attributes, validator) {
    if (!(this instanceof AWSResource)) {
        return new AWSResource(type, propdefinitions, name, properties, attributes, validator);
    }

    this.type = type;
    this.name = name;
    this.properties = properties;
    this.propdefinitions = propdefinitions;
    this.attributes = attributes;
    this.validator = validator;
}

AWSResource.prototype.validate = function() {
    var errors = [];
    var propdefinitions = this.propdefinitions;

    if (!this.name) {
        errors.push('You can\'t leave out the resource name ya ninny');
    }

    var diffKeys = _.difference(_.keys(this.properties), _.keys(propdefinitions));
    if (diffKeys.length > 0) {
        errors.push('Found unknown properties: ' + diffKeys.join(', '));
    }

    var mandatoryPropertyNames = _.reduce(propdefinitions, function(memo, value, key) {
        if (value.required === true) {
            memo.push(key);
        }
        return memo;
    }, []);
    var self = this;

    // check if mandatory properties are set
    mandatoryPropertyNames.forEach(function(propname) {
        var propvalue = self.properties[propname];
        if (typeof propvalue === 'undefined') {
            errors.push(util.format('Mandatory property "%s" is not set', propname));
        }
    });

    if (typeof this.validator === 'function') {
        var result = this.validator(this.properties);
        if (typeof result !== 'undefined') {
            errors.push(util.format('Failed validation: "%s"', result));
        }
    }

    var propertyNames = _.keys(this.properties);
    propertyNames.forEach(function(propname) {
        var propvalue = self.properties[propname];
        var def = propdefinitions[propname] || {};
        var type = def.type;
        if (typeof type === 'undefined') {
            errors.push(util.format('Internal error, missing type for property "%s"', propname));<commit_msg>add some TODO comments<commit_after>'use strict';

var _ = require('lodash')
    , util = require('util');

function AWSResource(type, propdefinitions, name, properties, attributes, validator) {
    if (!(this instanceof AWSResource)) {
        return new AWSResource(type, propdefinitions, name, properties, attributes, validator);
    }

    this.type = type;
    this.name = name;
    this.properties = properties;
    this.propdefinitions = propdefinitions;
    this.attributes = attributes;
    this.validator = validator;
}

AWSResource.prototype.validate = function() {
    var errors = [];
    var propdefinitions = this.propdefinitions;

    if (!this.name) {
        errors.push('You can\'t leave out the resource name ya ninny');
    }

    var diffKeys = _.difference(_.keys(this.properties), _.keys(propdefinitions));
    if (diffKeys.length > 0) {
        errors.push('Found unknown properties: ' + diffKeys.join(', '));
    }

    var mandatoryPropertyNames = _.reduce(propdefinitions, function(memo, value, key) {
        if (value.required === true) {
            memo.push(key);
        }
        return memo;
    }, []);
    var self = this; // TODO: remove this, use lambdas below

    // check if mandatory properties are set
    mandatoryPropertyNames.forEach(function(propname) {
        var propvalue = self.properties[propname];
        if (typeof propvalue === 'undefined') { // TODO: use a if (key in object) test
            errors.push(util.format('Mandatory property "%s" is not set', propname));
        }
    });

    if (typeof this.validator === 'function') {
        var result = this.validator(this.properties);
        if (typeof result !== 'undefined') {
            errors.push(util.format('Failed validation: "%s"', result));
        }
    }

    var propertyNames = _.keys(this.properties);
    propertyNames.forEach(function(propname) {
        var propvalue = self.properties[propname];
        var def = propdefinitions[propname] || {};
        var type = def.type;
        if (typeof type === 'undefined') {
            errors.push(util.format('Internal error, missing type for property "%s"', propname));
{'fraction_non_alphanumeric': 0.13271604938271606, 'fraction_numerical': 0.0004748338081671415, 'mean_word_length': 2.8865313653136533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '797044', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1161, 'n_words': 300}