<commit_before>var grunt = require('grunt');
var log = require('grunt-legacy-log');
var stream = require('readable-stream');
var inherits = require('inherits');
var rimraf = require('rimraf');
var multiTasks = [];

function BufferStream(done, options) {
  stream.Writable.call(this, options);

  var data = [];

  this._write = function (chunk, encoding, callback) {
    data.push(chunk);
    callback();
  };
  this.on('finish', function () {
    done(null, Buffer.concat(data));
  });
  this.on('error', function (err) {
    done(err);
  });
}
inherits(BufferStream, stream.Writable);

grunt.registerMultiTask = (function (obj, method) {
  return function (name) {
    multiTasks.push(name);
    method.apply(obj, arguments);
  };
})(grunt.task, grunt.task.registerMultiTask);

function Task(name, config) {
  if (!(this instanceof Task)) {
    return new Task(name, config);
  }

  var args = name.split(':');

  this.grunt = grunt;
  this.grunt.log = new log.Log({muted: true});
  this.grunt.verbose = this.grunt.log.verbose;
  this.name = args.shift();
  this.multi = multiTasks.indexOf(this.name) >= 0;
  this.target = this.multi ? args.shift() : null;
  this.args = args;
  this.data = {};
  this.files = [];
  this.stdout = null;

  this.grunt.config.set(this.name, config || {});
}

Task.prototype.run = function (/* [arguments...], done */) {
  var args = this.args.concat([].slice.apply(arguments));
  var task = this;

  if (task.target) {
    args.unshift(task.target);
  } else if (task.multi) {
    args.unshift('');
  }
  args.unshift(task.name);

  function run(done) {
    var warn = task.grunt.fail.warn;
    var fatal = task.grunt.fail.fatal;
    var outStream = task.grunt.log.options.outStream;
    var config = task.grunt.config.get(task.name);
    var finished = false;

    function end() {
      if (!finished) {
        finished = true;

        task.grunt.log.options.outStream.end();
        task.grunt.log.options.outStream = outStream;
        task.grunt.fail.warn = warn;
        task.grunt.fail.fatal = fatal;

        done.apply(this, arguments);
      }
    }

    task.target = task.multi ? (task.target || Object.keys(config)[0] || 'default') : null;
    task.data = task.multi ? config[task.target] : config;
    task.files = task.grunt.task.normalizeMultiTaskFiles(task.data, task.target);

    task.grunt.log.options.outStream = new BufferStream(function (err, data) {
      task.stdout = data;
    });

    task.grunt.fail.warn = end;
    task.grunt.fail.fatal = end;

    task.grunt.task.options({
      error: end,
      done: end
    });

    task.grunt.task.run(args.join(':'));
    task.grunt.task.start({asyncDone: true});
  }

  if (typeof args[args.length-1] === 'function') {
    run(args.pop());
    return this;
  } else {
    return run;
  }
};

Task.prototype.fail = function() {
  var args = [].slice.apply(arguments);
  var task = this;

  function expectError(done) {
    return function (err) {
      if (!err) {
        done(new Error('Expected ' + task.name + ' task to fail'));
      } else {
        done(null, err);
      }
    };
  }

  if (typeof args[args.length-1] === 'function') {
    args.push(expectError(args.pop()));
    return task.run.apply(task, args);
  } else {
    return function(done) {
      args.push(expectError(done));
      task.run.apply(task, args);
    };
  }
};

Task.prototype.clean = function(/* [files...], [done] */) {
  var args = [].slice.apply(arguments);
  var task = this;

  function clean(done) {
    var remain = task.files.length;

    function one(err) {
      if (err && remain > 0) {
        remain = 0;
        return done(err);
      }

      remain -= 1;
      if (remain === 0) {
        done();
      }
    }

    task.files.forEach(function (file) {
      rimraf(file.dest, one);
    });
  }

  if (typeof args[args.length-1] === 'function') {
    clean(args.pop());
    return this;
  } else {
    return clean;
  }
};

function runTask(name, config /* [arguments...], [done] */) {
  var task = new Task(name, config);

  return task.run.apply(task, [].slice.call(arguments, 2));
}

runTask.task = function create(name, config) {
  return new Task(name, config);
};

[ 'initConfig',
  'registerTask',
  'registerMultiTask',
  'renameTask',
  'loadTasks',
  'loadNpmTasks' ].forEach(function (fn) {
  runTask[fn] = grunt[fn].bind(grunt);
});

module.exports = runTask;<commit_msg>If no files to rmeove: do nothing<commit_after>var grunt = require('grunt');
var log = require('grunt-legacy-log');
var stream = require('readable-stream');
var inherits = require('inherits');
var rimraf = require('rimraf');
var multiTasks = [];

function BufferStream(done, options) {
  stream.Writable.call(this, options);

  var data = [];

  this._write = function (chunk, encoding, callback) {
    data.push(chunk);
    callback();
  };
  this.on('finish', function () {
    done(null, Buffer.concat(data));
  });
  this.on('error', function (err) {
    done(err);
  });
}
inherits(BufferStream, stream.Writable);

grunt.registerMultiTask = (function (obj, method) {
  return function (name) {
    multiTasks.push(name);
    method.apply(obj, arguments);
  };
})(grunt.task, grunt.task.registerMultiTask);

function Task(name, config) {
  if (!(this instanceof Task)) {
    return new Task(name, config);
  }

  var args = name.split(':');

  this.grunt = grunt;
  this.grunt.log = new log.Log({muted: true});
  this.grunt.verbose = this.grunt.log.verbose;
  this.name = args.shift();
  this.multi = multiTasks.indexOf(this.name) >= 0;
  this.target = this.multi ? args.shift() : null;
  this.args = args;
  this.data = {};
  this.files = [];
  this.stdout = null;

  this.grunt.config.set(this.name, config || {});
}

Task.prototype.run = function (/* [arguments...], done */) {
  var args = this.args.concat([].slice.apply(arguments));
  var task = this;

  if (task.target) {
    args.unshift(task.target);
  } else if (task.multi) {
    args.unshift('');
  }
  args.unshift(task.name);

  function run(done) {
    var warn = task.grunt.fail.warn;
    var fatal = task.grunt.fail.fatal;
    var outStream = task.grunt.log.options.outStream;
    var config = task.grunt.config.get(task.name);
    var finished = false;

    function end() {
      if (!finished) {
        finished = true;

        task.grunt.log.options.outStream.end();
        task.grunt.log.options.outStream = outStream;
        task.grunt.fail.warn = warn;
        task.grunt.fail.fatal = fatal;

        done.apply(this, arguments);
      }
    }

    task.target = task.multi ? (task.target || Object.keys(config)[0] || 'default') : null;
    task.data = task.multi ? config[task.target] : config;
    task.files = task.grunt.task.normalizeMultiTaskFiles(task.data, task.target);

    task.grunt.log.options.outStream = new BufferStream(function (err, data) {
      task.stdout = data;
    });

    task.grunt.fail.warn = end;
    task.grunt.fail.fatal = end;

    task.grunt.task.options({
      error: end,
      done: end
    });

    task.grunt.task.run(args.join(':'));
    task.grunt.task.start({asyncDone: true});
  }

  if (typeof args[args.length-1] === 'function') {
    run(args.pop());
    return this;
  } else {
    return run;
  }
};

Task.prototype.fail = function() {
  var args = [].slice.apply(arguments);
  var task = this;

  function expectError(done) {
    return function (err) {
      if (!err) {
        done(new Error('Expected ' + task.name + ' task to fail'));
      } else {
        done(null, err);
      }
    };
  }

  if (typeof args[args.length-1] === 'function') {
    args.push(expectError(args.pop()));
    return task.run.apply(task, args);
  } else {
    return function(done) {
      args.push(expectError(done));
      task.run.apply(task, args);
    };
  }
};

Task.prototype.clean = function(/* [files...], [done] */) {
  var args = [].slice.apply(arguments);
  var task = this;

  function clean(done) {
    var remain = task.files.length;

    function one(err) {
      if (err && remain > 0) {
        remain = 0;
        return done(err);
      }

      remain -= 1;
      if (remain === 0) {
        done();
      }
    }

    if (remain) {
      task.files.forEach(function (file) {
        rimraf(file.dest, one);
      });
    } else {
      done();
    }
  }

  if (typeof args[args.length-1] === 'function') {
    clean(args.pop());
    return this;
  } else {
    return clean;
  }
};

function runTask(name, config /* [arguments...], [done] */) {
  var task = new Task(name, config);

  return task.run.apply(task, [].slice.call(arguments, 2));
}

runTask.task = function create(name, config) {
  return new Task(name, config);
};

[ 'initConfig',
  'registerTask',
  'registerMultiTask',
  'renameTask',
  'loadTasks',
  'loadNpmTasks' ].forEach(function (fn) {
  runTask[fn] = grunt[fn].bind(grunt);
});

module.exports = runTask;
{'fraction_non_alphanumeric': 0.17492382349621938, 'fraction_numerical': 0.002257081593499605, 'mean_word_length': 2.824773413897281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '992560', 'n_tokens_mistral': 3088, 'n_tokens_neox': 3024, 'n_words': 611}