<commit_before>var i18n = require('i18next-client');
var prettyCSS = require('PrettyCSS');
var Promise = require('es6-promise').Promise;

var humanErrors = {
  'block-expected': function(error) {
    return i18n.t(
      'errors.prettycss.block-expected',
      {error: error.token.content}
    );
  },

  'extra-tokens-after-value': function() {
    return i18n.t('errors.prettycss.extra-tokens-after-value');
  },

  'illegal-token-after-combinator': function() {
    return i18n.t('errors.prettycss.illegal-token-after-combinator');
  },

  'invalid-token': function() {
    return i18n.t('errors.prettycss.invalid-token');
  },

  'invalid-value': function(error) {
    return i18n.t(
      'errors.prettycss.invalid-value',
      {error: error.token.content}
    );
  },

  'require-value': function(error) {
    return i18n.t(
      'errors.prettycss.require-value',
      {error: error.token.content}
    );
  },

  'selector-expected': function() {
    return i18n.t('errors.prettycss.selector-expected');
  },

  'unknown-property': function(error) {
    return i18n.t(
      'errors.prettycss.unknown-property',
      {error: error.token.content}
    );
  },
};

function convertErrorToAnnotation(error) {
  var normalizedCode = error.code.split(':')[0];
  if (error.token !== null && humanErrors.hasOwnProperty(normalizedCode)) {
    var message = humanErrors[normalizedCode](error);
    return {
      row: error.token.line - 1, column: error.token.charNum - 1,
      raw: message,
      text: message,
      type: 'error',
    };
  }
}

module.exports = function(source) {
  var result = prettyCSS.parse(source);
  var annotations = [];
  result.errors.concat(result.warnings).forEach(function(error) {
    var annotation = convertErrorToAnnotation(error);
    if (annotation !== undefined) {
      annotations.push(annotation);
    }
  });
  return Promise.resolve(annotations);
};
<commit_msg>Ignore error messages caused by PrettyCSS not recognizing radial-gradient<commit_after>var i18n = require('i18next-client');
var prettyCSS = require('PrettyCSS');
var Promise = require('es6-promise').Promise;

var RADIAL_GRADIENT_EXPR =
  /^(?:(?:-(?:ms|moz|o|webkit)-)?radial-gradient|-webkit-gradient)/;
function isIncorrectlyRejectedRadialGradientValue(value) {
  return RADIAL_GRADIENT_EXPR.test(value);
}

var humanErrors = {
  'block-expected': function(error) {
    return i18n.t(
      'errors.prettycss.block-expected',
      {error: error.token.content}
    );
  },

  'extra-tokens-after-value': function() {
    return i18n.t('errors.prettycss.extra-tokens-after-value');
  },

  'illegal-token-after-combinator': function() {
    return i18n.t('errors.prettycss.illegal-token-after-combinator');
  },

  'invalid-token': function() {
    return i18n.t('errors.prettycss.invalid-token');
  },

  'invalid-value': function(error) {
    if (isIncorrectlyRejectedRadialGradientValue(error.token.content)) {
      return;
    }

    return i18n.t(
      'errors.prettycss.invalid-value',
      {error: error.token.content}
    );
  },

  'require-value': function(error) {
    return i18n.t(
      'errors.prettycss.require-value',
      {error: error.token.content}
    );
  },

  'selector-expected': function() {
    return i18n.t('errors.prettycss.selector-expected');
  },

  'unknown-property': function(error) {
    return i18n.t(
      'errors.prettycss.unknown-property',
      {error: error.token.content}
    );
  },
};

function convertErrorToAnnotation(error) {
  var normalizedCode = error.code.split(':')[0];
  if (error.token !== null && humanErrors.hasOwnProperty(normalizedCode)) {
    var message = humanErrors[normalizedCode](error);
    if (message !== undefined) {
      return {
        row: error.token.line - 1, column: error.token.charNum - 1,
        raw: message,
        text: message,
        type: 'error',
      };
    }
  }
}

module.exports = function(source) {
  var result = prettyCSS.parse(source);
  var annotations = [];
  result.errors.concat(result.warnings).forEach(function(error) {
    var annotation = convertErrorToAnnotation(error);
    if (annotation !== undefined) {
      annotations.push(annotation);
    }
  });
  return Promise.resolve(annotations);
};

{'fraction_non_alphanumeric': 0.15774514448128849, 'fraction_numerical': 0.011369019422074847, 'mean_word_length': 3.4687830687830687, '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': '6179904', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1354, 'n_words': 215}