<commit_before>import path from 'path';
import chProcess from 'child_process';
import chalk from 'chalk';
import Promise from 'bluebird';

import TaskCollector from './TaskCollector';

const taskCollector = new TaskCollector();

export { Promise };

export function processArgs([name, ...args]) {
    if (!name) {
        taskCollector.printHelp();
        return Promise.resolve();
    }
    return taskCollector.runTask(name, args.slice(1), true);
}

export function task(name, fn, options) {
    return taskCollector.addTask(name, fn, options);
}

function validateTaskToExecute(name, item, arrayCount = 0) {
    if (Array.isArray(item) && arrayCount < 2) {
        item.forEach(i => validateTaskToExecute(name, i, arrayCount + 1));
    } else if (typeof item !== 'string') {
        throw new Error(`Task ${name} ' tasks ${item} is not a string`);
    }
}

export function taskGroup(name, tasksToExecute, options) {
    validateTaskToExecute(name, tasksToExecute);

    return taskCollector.addTask(name, (...args) => {
        return tasksToExecute.reduce((accumulator, currentValue) => {
            return accumulator.then((res) => {
                if (Array.isArray(currentValue)) {
                    return Promise.all(currentValue.map(t => taskCollector.runTask(t, args, false)));
                }
                return taskCollector.runTask(currentValue, args, false);
            });
        }, Promise.resolve());
    }, options);
}

export function runTask(name, ...args) {
    return taskCollector.runTask(name, args, false);
}

export function run(cmd, options = {}) {
    /* eslint-disable no-param-reassign */
    options.env = options.env || process.env;
    options.stream = options.stream || true;
    options.canFail = options.canFail || false;
    const envPath = options.env.PATH ? options.env.PATH : process.env.PATH;
    options.env.PATH = [path.join(process.cwd(), 'node_modules', '.bin'), envPath].join(path.delimiter);
    /* eslint-enable no-param-reassign */

    console.log(chalk.bold(`>>> Executing ${chalk.cyan(cmd)}`));
    return new Promise((resolve, reject) => {
        const cmdProcess = chProcess.exec(cmd, options, (error, stdout) => {
            if (error) {
                if (options.canFail) {
                    reject(error);
                } else {
                    resolve(error);
                }
            } else {
                resolve(stdout);
            }
        });

        if (options.stream) {
            cmdProcess.stdout.pipe(process.stdout);
        }
    });
}
<commit_msg>Fixed some more linting issues<commit_after>import path from 'path';
import chProcess from 'child_process';
import chalk from 'chalk';
import Promise from 'bluebird';

import TaskCollector from './TaskCollector';

const taskCollector = new TaskCollector();

export { Promise };

export function processArgs([name, ...args]) {
    if (!name) {
        taskCollector.printHelp();
        return Promise.resolve();
    }
    return taskCollector.runTask(name, args.slice(1), true);
}

export function task(name, fn, options) {
    return taskCollector.addTask(name, fn, options);
}

function validateTaskToExecute(name, item, arrayCount = 0) {
    if (Array.isArray(item) && arrayCount < 2) {
        item.forEach(i => validateTaskToExecute(name, i, arrayCount + 1));
    } else if (typeof item !== 'string') {
        throw new Error(`Task ${name} ' tasks ${item} is not a string`);
    }
}

export function taskGroup(name, tasksToExecute, options) {
    validateTaskToExecute(name, tasksToExecute);

    return taskCollector.addTask(name, (...args) => (
        tasksToExecute.reduce((accumulator, currentValue) => (
            accumulator.then(() => {
                if (Array.isArray(currentValue)) {
                    return Promise.all(currentValue.map(t => taskCollector.runTask(t, args, false)));
                }
                return taskCollector.runTask(currentValue, args, false);
            })
        ), Promise.resolve())
    ), options);
}

export function runTask(name, ...args) {
    return taskCollector.runTask(name, args, false);
}

export function run(cmd, options = {}) {
    /* eslint-disable no-param-reassign */
    options.env = options.env || process.env;
    options.stream = options.stream || true;
    options.canFail = options.canFail || false;
    const envPath = options.env.PATH ? options.env.PATH : process.env.PATH;
    options.env.PATH = [path.join(process.cwd(), 'node_modules', '.bin'), envPath].join(path.delimiter);
    /* eslint-enable no-param-reassign */

    console.log(chalk.bold(`>>> Executing ${chalk.cyan(cmd)}`));
    return new Promise((resolve, reject) => {
        const cmdProcess = chProcess.exec(cmd, options, (error, stdout) => {
            if (error) {
                if (options.canFail) {
                    reject(error);
                } else {
                    resolve(error);
                }
            } else {
                resolve(stdout);
            }
        });

        if (options.stream) {
            cmdProcess.stdout.pipe(process.stdout);
        }
    });
}

{'fraction_non_alphanumeric': 0.14084507042253522, 'fraction_numerical': 0.001564945226917058, 'mean_word_length': 2.51892635925671, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '7267222', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1460, 'n_words': 332}