<commit_before>var fs    = require('fs'),
    path  = require('path'),
    spawn = require('child_process').spawn;

module.exports = {

  config: {
    binary: {
      type: "string",
      default: "/usr/local/bin/perltidy"
    },
    options: {
      type: "array",
      default: ["--pro=.../.perltidyrc"],
      items: {
        type: "string"
      }
    }
  },

  activate: function() {
    atom.commands.add('atom-workspace', 'perltidy:tidy', function() {

      var editor  = atom.workspace.getActiveTextEditor();
      var cwd     = path.dirname(editor.getPath());
      var binary  = atom.config.get('perltidy.binary');
      var options = atom.config.get('perltidy.options');

      if (fs.existsSync(binary)) {
        var position = editor.getCursorScreenPosition();
        perlTidy(binary, cwd, options, editor.getText(), function (perl) {
          editor.transact(function() {
            editor.setText(perl);
            editor.getLastCursor().setScreenPosition(position);
          });
        });
      }

      else {
        editor.setText('No Perltidy found at "' + path + '".');
      }
    });
  }
};

function perlTidy(binary, cwd, options, before, cb) {

  var after = '';
  var perltidy = spawn(binary, options, { cwd: cwd, stdio: 'pipe' });
  perltidy.stdin.setEncoding  = 'utf-8';
  perltidy.stdout.setEncoding = 'utf-8';
  perltidy.stdin.end(before);
  perltidy.on('exit', function() {
    cb(after);
  });
  perltidy.stdout.on('data', function(chunk) {
    after += chunk;
  });
}<commit_msg>fix error message<commit_after>var fs    = require('fs'),
    path  = require('path'),
    spawn = require('child_process').spawn;

module.exports = {

  config: {
    binary: {
      type: "string",
      default: "/usr/local/bin/perltidy"
    },
    options: {
      type: "array",
      default: ["--pro=.../.perltidyrc"],
      items: {
        type: "string"
      }
    }
  },

  activate: function() {
    atom.commands.add('atom-workspace', 'perltidy:tidy', function() {

      var editor  = atom.workspace.getActiveTextEditor();
      var cwd     = path.dirname(editor.getPath());
      var binary  = atom.config.get('perltidy.binary');
      var options = atom.config.get('perltidy.options');

      if (fs.existsSync(binary)) {
        var position = editor.getCursorScreenPosition();
        perlTidy(binary, cwd, options, editor.getText(), function (perl) {
          editor.transact(function() {
            editor.setText(perl);
            editor.getLastCursor().setScreenPosition(position);
          });
        });
      }

      else {
        editor.setText('No Perltidy found at "' + binary + '".');
      }
    });
  }
};

function perlTidy(binary, cwd, options, before, cb) {

  var after = '';
  var perltidy = spawn(binary, options, {cwd: cwd, stdio: 'pipe'});
  perltidy.stdin.setEncoding  = 'utf-8';
  perltidy.stdout.setEncoding = 'utf-8';
  perltidy.stdin.end(before);
  perltidy.on('exit', function() {
    cb(after);
  });
  perltidy.stdout.on('data', function(chunk) {
    after += chunk;
  });
}
{'fraction_non_alphanumeric': 0.17026850032743943, 'fraction_numerical': 0.0013097576948264572, 'mean_word_length': 2.515535097813579, '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': '840160', 'n_tokens_mistral': 1013, 'n_tokens_neox': 997, 'n_words': 176}