<commit_before>var validateOne = function(validatorFunction, fieldName) {
  // Get field value.
  var value = this.get(fieldName);

  try {
    // Run validator function which throws exception which we have to catch and
    // add error message to appropriate field.
    validatorFunction.call(this, value, fieldName);

    return true;
  } catch (e) {
    if (e instanceof ValidationError) {
      this._errors.set(fieldName, e.message);
    } else {
      throw e;
    }

    return false;
  }
};

var validate = function(fieldName) {
  // Functions "schema.getValidator" and "schema.getValidators" get validation
  // data defined in the given class schema not global validator object.

  // Get schema for given object instance.
  var schema = this.constructor.schema;

  // At first clear list of all error messages.
  var validators = schema.getValidators();
  _.each(validators, function(validator, fieldName) {
    this._errors.set(fieldName, undefined);
  }, this);

  var isValid = true;
  if (fieldName) {
    // Get validation function for given field name.
    var validatorFunction = schema.getValidator(fieldName);

    // Validate field only if there is validation function.
    if (validatorFunction) {
      isValid = validateOne.call(this, validatorFunction, fieldName);
    }
  } else {
    // Get schema validators and run each one.
    isValid = _.all(validators, validateOne, this);
  }

  // Set reactive object's error indicator.
  this._hasError.set(!isValid);

  return isValid;
};

var getError = function(fieldName) {
  return this._errors.get(fieldName);<commit_msg>Fix hasError to have correct value<commit_after>var validateOne = function(validatorFunction, fieldName) {
  // Get field value.
  var value = this.get(fieldName);

  try {
    // Run validator function which throws exception which we have to catch and
    // add error message to appropriate field.
    validatorFunction.call(this, value, fieldName);

    // If a field's validation didn't throw an exception then clear an error
    // message for the given field.
    this._errors.set(fieldName, undefined);

    return true;
  } catch (e) {
    if (e instanceof ValidationError) {
      this._errors.set(fieldName, e.message);
    } else {
      throw e;
    }

    return false;
  }
};

var validate = function(fieldName) {
  // Functions "schema.getValidator" and "schema.getValidators" get validation
  // data defined in the given class schema not global validator object.

  // Get schema for given object instance.
  var schema = this.constructor.schema;

  // Get list all of all validators.
  var validators = schema.getValidators();

  var isValid = true;
  if (fieldName) {
    // Get validation function for given field name.
    var validatorFunction = validators[fieldName];

    // Validate field only if there is validation function.
    if (validatorFunction) {
      isValid = validateOne.call(this, validatorFunction, fieldName);
    }

    // When the given field passed validation, we have to check how many errors
    // we still have and decide whether the "_hasErrors" reactive var should be
    // set.
    this._hasError.set(
      !_.isUndefined(
        _.find(validators, function(validator, fieldName) {
          return this._errors.get(fieldName);
        }, this)
      )
    );
  } else {
    // Get schema validators and run each one.
    isValid = _.all(validators, validateOne, this);

    // Set reactive object's error indicator.
    this._hasError.set(!isValid);
  }

  return isValid;
};

var getError = function(fieldName) {
  return this._errors.get(fieldName);
{'fraction_non_alphanumeric': 0.0968906163242643, 'fraction_numerical': 0.0, 'mean_word_length': 3.048314606741573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2840726', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1004, 'n_words': 343}