<commit_before>import plainGetIn from './structure/plain/getIn'

const getErrorKeys = (name, type) => {
  switch (type) {
    case 'Field':
      return [ name, `${name}._error` ]
    case 'FieldArray':
      return [ `${name}._error` ]
    default:
      throw new Error('Unknown field type')
  }
}

const createHasError = ({ getIn }) => {
  const hasError = (field, syncErrors, asyncErrors, submitErrors) => {
    if (!syncErrors && !asyncErrors && !submitErrors) {
      return false
    }

    const name = getIn(field, 'name')
    const type = getIn(field, 'type')
    return getErrorKeys(name, type).some(key =>
      plainGetIn(syncErrors, key) ||
      getIn(asyncErrors, key) ||
      getIn(submitErrors, key))
  }
  return hasError
}

export default createHasError<commit_msg>Fix: hasError used plain.getIn(syncErrors, key) for Immutable instead of getIn(syncErrors, key) (#2755)<commit_after>const getErrorKeys = (name, type) => {
  switch (type) {
    case 'Field':
      return [ name, `${name}._error` ]
    case 'FieldArray':
      return [ `${name}._error` ]
    default:
      throw new Error('Unknown field type')
  }
}

const createHasError = ({ getIn }) => {
  const hasError = (field, syncErrors, asyncErrors, submitErrors) => {
    if (!syncErrors && !asyncErrors && !submitErrors) {
      return false
    }

    const name = getIn(field, 'name')
    const type = getIn(field, 'type')
    return getErrorKeys(name, type).some(key =>
      getIn(syncErrors, key) ||
      getIn(asyncErrors, key) ||
      getIn(submitErrors, key))
  }
  return hasError
}

export default createHasError
{'fraction_non_alphanumeric': 0.14250155569383946, 'fraction_numerical': 0.002489110143123833, 'mean_word_length': 3.299465240641711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5126264', 'n_tokens_mistral': 511, 'n_tokens_neox': 508, 'n_words': 130}