<commit_before>'use strict';

var fs = require('fs');
var RSVP = require('rsvp');
var api = require('../../api');
var utils = require('../../utils');
var chalk = require('chalk');

module.exports = function(context, options, payload) {
  var rulesPath = options.config.get('storage.rules');
  if (rulesPath) {
    rulesPath = options.config.path(rulesPath);
    var src = fs.readFileSync(rulesPath, 'utf8');
    return api.request('POST', '/v1/projects/' + options.project + ':test', {
      origin: api.rulesOrigin,
      data: {
        source: {
          files: [{
            content: src,
            name: 'storage.rules'
          }]
        }
      },
      auth: true
    }).then(function(response) {
      if (response.body && response.body.issues && response.body.issues.length > 0) {
        var add = response.body.issues.length === 1 ? '' : 's';
        var message = 'Compilation error' + add + ' in ' + chalk.bold(options.config.get('storage.rules')) + ':\n';
        response.body.issues.forEach(function(issue) {
          message += '\n[' + issue.severity.substring(0, 1) + '] ' + issue.sourcePosition.line + ':' + issue.sourcePosition.column + ' - ' + issue.description;
        });

        return utils.reject(message, {exit: 1});
      }

      utils.logBullet(chalk.cyan('storage:') + ' rules file compiled successfully');
      payload.storage = {rules: [
        {name: options.config.get('storage.rules'), content: src}
      ]};
      return RSVP.resolve();
    });
  }

  return RSVP.resolve();
};<commit_msg>Update print output to match new paradigm<commit_after>'use strict';

var fs = require('fs');
var RSVP = require('rsvp');
var api = require('../../api');
var utils = require('../../utils');
var chalk = require('chalk');

module.exports = function(context, options, payload) {
  var rulesPath = options.config.get('storage.rules');
  if (rulesPath) {
    rulesPath = options.config.path(rulesPath);
    var src = fs.readFileSync(rulesPath, 'utf8');
    utils.logBullet(chalk.bold.cyan('storage:') + ' checking rules for compilation errors...');
    return api.request('POST', '/v1/projects/' + options.project + ':test', {
      origin: api.rulesOrigin,
      data: {
        source: {
          files: [{
            content: src,
            name: 'storage.rules'
          }]
        }
      },
      auth: true
    }).then(function(response) {
      if (response.body && response.body.issues && response.body.issues.length > 0) {
        var add = response.body.issues.length === 1 ? '' : 's';
        var message = 'Compilation error' + add + ' in ' + chalk.bold(options.config.get('storage.rules')) + ':\n';
        response.body.issues.forEach(function(issue) {
          message += '\n[' + issue.severity.substring(0, 1) + '] ' + issue.sourcePosition.line + ':' + issue.sourcePosition.column + ' - ' + issue.description;
        });

        return utils.reject(message, {exit: 1});
      }

      utils.logSuccess(chalk.bold.green('storage:') + ' rules file compiled successfully');
      payload.storage = {rules: [
        {name: options.config.get('storage.rules'), content: src}
      ]};
      return RSVP.resolve();
    });
  }

  return RSVP.resolve();
};
{'fraction_non_alphanumeric': 0.1794951698348395, 'fraction_numerical': 0.004362729822374571, 'mean_word_length': 2.639455782312925, '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': '6412162', 'n_tokens_mistral': 989, 'n_tokens_neox': 960, 'n_words': 200}