<commit_before>import { includes, difference, uniq } from 'lodash';

/**
 * Validate conditional rules
 * @param key
 * @param attributeTypes
 * @param attributes
 * @returns {Boolean}
 */
export const validateConditionalRules = (key, attributeTypes, attributes) => {
  const requiredIf = attributeTypes[key].requiredIf;
  Object.keys(attributes).forEach(attribute => {
    // for each attribute
    Object.keys(requiredIf).forEach(item => {
      // for each item in requiredIf
      if (requiredIf.hasOwnProperty(item) && requiredIf[item].key === attribute) {
        // if requiredIf has attribute
        if (includes(requiredIf[item].values, attributes[attribute].value)) {
          // if requiredIf has same value as attribute
          return true;
        }
      }
    });
  });
  return false;
};

/**
 * @typedef {function(obj:Object, rules:Object):string[]} Validator
 */
/**
 * @param  {string} type
 * @return {Validator}]
 */
const createValidateErrors = type => (obj, rules) => {
  const errors = [];
  Object.keys(rules).forEach(key => {
    if (rules.hasOwnProperty(key)) {
      const rule = rules[key];
      const isRequired = rules[key].required;
      const isRequiredInType = includes(rule.requiredIn, type);
      const objHasRuleAttribute = !!obj.attributes[key];
      const isAttributeAllowedInType = includes(rules[key].allowedIn, type);
      const isValid =
        includes(rule.values.map(obj => obj.value), obj.attributes[key]) ||
        rule.values.length === 0;
      const allowValuesOutsideChoices = includes(
        rule.allowValuesOutsideChoicesIn,
        type
      );<commit_msg>Fixed editor form not showing all fields<commit_after>import { includes, difference, uniq } from 'lodash';

/**
 * Validate conditional rules
 * @param key
 * @param attributeTypes
 * @param attributes
 * @returns {Boolean}
 */
export const validateConditionalRules = (key, attributeTypes, attributes) => {
  const requiredIf = attributeTypes[key].requiredIf;
  let valid = false;
  Object.keys(attributes).forEach(attribute => {
    // for each attribute
    requiredIf.forEach(item => {
      // for each item in requiredIf
      if (item.key === attribute) {
        // if requiredIf has attribute
        if (includes(item.values, attributes[attribute].value)) {
          // if requiredIf has same value as attribute
          valid = true;
        }
      }
    });
  });
  return valid;
};

/**
 * @typedef {function(obj:Object, rules:Object):string[]} Validator
 */
/**
 * @param  {string} type
 * @return {Validator}]
 */
const createValidateErrors = type => (obj, rules) => {
  const errors = [];
  Object.keys(rules).forEach(key => {
    if (rules.hasOwnProperty(key)) {
      const rule = rules[key];
      const isRequired = rules[key].required;
      const isRequiredInType = includes(rule.requiredIn, type);
      const objHasRuleAttribute = !!obj.attributes[key];
      const isAttributeAllowedInType = includes(rules[key].allowedIn, type);
      const isValid =
        includes(rule.values.map(obj => obj.value), obj.attributes[key]) ||
        rule.values.length === 0;
      const allowValuesOutsideChoices = includes(
        rule.allowValuesOutsideChoicesIn,
        type
      );
{'fraction_non_alphanumeric': 0.13170127052990394, 'fraction_numerical': 0.0006197706848466068, 'mean_word_length': 3.1597938144329896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3184598', 'n_tokens_mistral': 906, 'n_tokens_neox': 896, 'n_words': 220}