<commit_before>'use strict';

// Since we do not check for `empty` against `patchOp.argument` before
// model.ATTR resolution, we do it now
const checkEmpty = function ({ opVal, operator: { argument }, type }) {
  if (argument === undefined) { return; }

  const hasWrongNull = opVal == null && !argument.includes('empty');

  if (hasWrongNull) {
    return `the argument is invalid. Patch operator '${type}' argument must be not be empty`;
  }

  const hasWrongNulls = Array.isArray(opVal) &&
    opVal.includes(null) &&
    !argument.includes('empty[]');

  if (hasWrongNulls) {
    return `the argument is invalid. Patch operator '${type}' argument must be not contain empty items`;
  }
};

module.exports = {
  checkEmpty,
};
<commit_msg>Refactoring<commit_after>'use strict';

// Since we do not check for `empty` against `patchOp.argument` before
// model.ATTR resolution, we do it now
const checkEmpty = function ({ opVal, operator: { argument }, type }) {
  if (argument === undefined) { return; }

  if (hasWrongNull({ opVal, argument })) {
    return `the argument is invalid. Patch operator '${type}' argument must be not be empty`;
  }

  if (hasWrongNulls({ opVal, argument })) {
    return `the argument is invalid. Patch operator '${type}' argument must be not contain empty items`;
  }
};

const hasWrongNull = function ({ opVal, argument }) {
  return opVal == null && !argument.includes('empty');
};

const hasWrongNulls = function ({ opVal, argument }) {
  return Array.isArray(opVal) &&
    opVal.includes(null) &&
    !argument.includes('empty[]');
};

module.exports = {
  checkEmpty,
};

{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0, 'mean_word_length': 3.9876160990712073, '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': '4208133', 'n_tokens_mistral': 491, 'n_tokens_neox': 482, 'n_words': 160}