<commit_before>import * as React from "react";
import PropTypes from "prop-types";
import Image, { badgeSizes } from "@crave/farmblocks-image";
import Text from "@crave/farmblocks-text";
import { fontSizes } from "@crave/farmblocks-theme";

import MessageWrapper from "./styledComponents/MessageWrapper";
import errorIconSrc from "./constants/errorIcon";

export const withMessagesProps = {
  errorIconSrc: PropTypes.string,
  validationMessages: PropTypes.arrayOf(PropTypes.string),
  onInvalid: PropTypes.func
};

const withMessages = WrappedComponent => {
  return class ValidationMessages extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        messages: props.validationMessages
      };

      this.onInvalid = this.onInvalid.bind(this);
      this.onChange = this.onChange.bind(this);
      this.hasPropsValidations = this.hasPropsValidations.bind(this);
    }

    componentWillReceiveProps(nextProps) {
      if (nextProps.validationMessages !== this.props.validationMessages) {
        this.setState({
          messages: nextProps.validationMessages
        });
      }
    }

    hasPropsValidations() {
      return this.props.validationMessages.length !== 0;
    }

    onInvalid(event) {
      event.preventDefault();
      // use built-in browser validation message if available and if the validationErrors is not passed
      if (!this.hasPropsValidations() && event.target.validationMessage) {
        this.setState({
          messages: [event.target.validationMessage]
        });
      }
      return this.props.onInvalid(event);<commit_msg>refactor: refactor withMessages constructor<commit_after>import * as React from "react";
import PropTypes from "prop-types";
import Image, { badgeSizes } from "@crave/farmblocks-image";
import Text from "@crave/farmblocks-text";
import { fontSizes } from "@crave/farmblocks-theme";

import MessageWrapper from "./styledComponents/MessageWrapper";
import errorIconSrc from "./constants/errorIcon";

export const withMessagesProps = {
  errorIconSrc: PropTypes.string,
  validationMessages: PropTypes.arrayOf(PropTypes.string),
  onInvalid: PropTypes.func
};

const withMessages = WrappedComponent => {
  return class ValidationMessages extends React.Component {
    state = {
      messages: this.props.validationMessages
    };

    onInvalid = this.onInvalid.bind(this);
    onChange = this.onChange.bind(this);
    hasPropsValidations = this.hasPropsValidations.bind(this);

    componentWillReceiveProps(nextProps) {
      if (nextProps.validationMessages !== this.props.validationMessages) {
        this.setState({
          messages: nextProps.validationMessages
        });
      }
    }

    hasPropsValidations() {
      return this.props.validationMessages.length !== 0;
    }

    onInvalid(event) {
      event.preventDefault();
      // use built-in browser validation message if available and if the validationErrors is not passed
      if (!this.hasPropsValidations() && event.target.validationMessage) {
        this.setState({
          messages: [event.target.validationMessage]
        });
      }
      return this.props.onInvalid(event);
{'fraction_non_alphanumeric': 0.10651074589127686, 'fraction_numerical': 0.0006321112515802782, 'mean_word_length': 3.5408895265423244, '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': '5446117', 'n_tokens_mistral': 843, 'n_tokens_neox': 847, 'n_words': 186}