<commit_before>import React from 'react'
import higherOrderComponent from './higher_order_component.js'

@higherOrderComponent()
export default class ErrorNormalizer extends React.Component {
  static propTypes = {
    errors: React.PropTypes.oneOfType([
      React.PropTypes.object,
      React.PropTypes.array,
    ]),
  }
  displayName = 'Frig.HigherOrderComponents.ErrorNormalizer'


  _toErrorObject(errors) {
    const isArray = Array.isArray(errors)
    if (errors == null || (isArray && errors.length === 0)) return {}
    // If errors is an array then convert it into an object. 'base' is
    // used to store all top-level errors that are not specific to an
    // input.
    if (isArray) return { base: errors }

    return errors
  }

  _errors() {
    const errors = {}
    const errorsSubset = this._toErrorObject(this.props.errors)
    const errors = Object.keys(errorsSubset).map((k) =>
      (errors[k] || []).concat(errorsSubset[k])
    )
    return errors
  }

  _normalizedErrors() {
    const errors = this._errors()
    // let normalizedErrorClass = opts.as
    const normalizedErrorClass = this.opts().as
    // Convert the errors object into the normalized error class
    if (normalizedErrorClass === Array) {
      return errors.map((k) => errors[k])
    }
    if (normalizedErrorClass === Object) {
      return errors
    }

    throw new Error('ErrorsNormalizer \'as\' attribute must be either Array or Object')
  }

  render() {
    const ComponentClass = this.ComponentClass() // eslint-disable-line new-cap
    const childProps = Object.assign({}, this.props, {
      ref: 'child',
      errors: this._normalizedErrors(),
    })
    return <ComponentClass {...childProps} />
  }

}
<commit_msg>errors_normalizer: Refactor confusing _errors() method<commit_after>import React from 'react'
import higherOrderComponent from './higher_order_component.js'

@higherOrderComponent()
export default class ErrorNormalizer extends React.Component {
  static propTypes = {
    errors: React.PropTypes.oneOfType([
      React.PropTypes.object,
      React.PropTypes.array,
    ]),
  }
  displayName = 'Frig.HigherOrderComponents.ErrorNormalizer'


  _toErrorObject(errors) {
    const isArray = Array.isArray(errors)
    if (errors == null || (isArray && errors.length === 0)) return {}
    // If errors is an array then convert it into an object. 'base' is
    // used to store all top-level errors that are not specific to an
    // input.
    if (isArray) return { base: errors }

    return errors
  }

  _errors() {
    return this._toErrorObject(this.props.errors)
  }

  _normalizedErrors() {
    const errors = this._errors()
    // let normalizedErrorClass = opts.as
    const normalizedErrorClass = this.opts().as
    // Convert the errors object into the normalized error class
    if (normalizedErrorClass === Array) {
      return errors.map((k) => errors[k])
    }
    if (normalizedErrorClass === Object) {
      return errors
    }

    throw new Error('ErrorsNormalizer \'as\' attribute must be either Array or Object')
  }

  render() {
    const ComponentClass = this.ComponentClass() // eslint-disable-line new-cap
    const childProps = Object.assign({}, this.props, {
      ref: 'child',
      errors: this._normalizedErrors(),
    })
    return <ComponentClass {...childProps} />
  }

}

{'fraction_non_alphanumeric': 0.11618132692885019, 'fraction_numerical': 0.0006004202942059442, 'mean_word_length': 3.1186650185414093, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '7480228', 'n_tokens_mistral': 973, 'n_tokens_neox': 952, 'n_words': 270}