<commit_before>"use strict";

let check = function(pathToPackage) {

    const path = require('path');
    const Promise = require('bluebird');
    const exec = Promise.promisify(require('child_process').exec);
    const _ = require('lodash');
    const fs = require('fs');
    const jsonfile = require('jsonfile');
    const validaterRules = require('./validatorRules');
    const promiseHelpers = require('./promiseHelpers');

    let engines;

    const checkerResult = {
        status: 0,
        message: '',
        packages: []
    };

    const packageJsonPath = pathToPackage || path.join(process.cwd(), 'package.json');
    try {
        fs.accessSync(packageJsonPath);
        engines = jsonfile.readFileSync(packageJsonPath).engines;
    }
    catch (ex) {
        checkerResult.message = {
            text: '✘ No package.json found in the current directory so I can\'t validate what you need!',
            type: 'error'
        };
        checkerResult.status = -1;

        return Promise.resolve(checkerResult);
    }

    if (!engines) {
        checkerResult.message = {
            text: '✘ No engines found in package.json so I can\'t validate what you need!',
            type: 'error'
        };
        checkerResult.status = -1;

        return Promise.resolve(checkerResult);
    }

    const thingsToCheck = Object.getOwnPropertyNames(engines);
    const validatorPromises = thingsToCheck.map(validate); // run the function over all items.

    return promiseHelpers.allSettled(validatorPromises)
    .then((inspections) => {
        const environmentIsValid = _.every(inspections,
            (inspection) => inspection.isFulfilled() && inspection.value());

        if (environmentIsValid) {
            checkerResult.message = {
                text: 'Environment looks good!',
                type: 'success'
            };
        }
        else {
            checkerResult.message = {
                text: 'Environment is invalid!',
                type: 'error'
            };
        }
        return checkerResult;
    });

    function validate(name) {

        // find it in the validators
        const validator = validaterRules[name];

        if (validator === undefined) {
            checkerResult.packages.push({
                name: name,
                validatorFound: false,
                type: 'warn'
            });
            return Promise.resolve(false);
        }

        // call the validator and pass in the version we expect
        return execAndCheck(validator, engines[name]).then((results) => {
            if (results.result) {
                checkerResult.packages.push({
                    name: name,
                    validatorFound: true,
                    expectedVersion: engines[name],
                    foundVersion: engines[name],
                    type: 'success'
                });
            }
            else {
                checkerResult.packages.push({
                    name: name,
                    validatorFound: true,
                    expectedVersion: engines[name],
                    foundVersion: results.reason.trim() || 'missing',
                    type: 'error'
                });
            }

            return Promise.resolve(results.result);
        })
        .catch((error) => {
            checkerResult.packages.push({
                name: name,
                validatorFound: true,
                expectedVersion: engines[name],
                commandError: error,
                type: 'error'
            });
            return Promise.reject();
        });
    }

    function execAndCheck(validator, expectedVersion) {
        return exec(validator.versionCheck).then((result) => {
            return {
                result: validator.versionValidate(result, expectedVersion),
                reason: result
            };
        }).catch((e) => { throw e; });
    }
};
module.exports = check;
<commit_msg>making ESLint happy<commit_after>"use strict";

let check = function(pathToPackage) {

    const path = require('path');
    const Promise = require('bluebird');
    const exec = Promise.promisify(require('child_process').exec);
    const _ = require('lodash');
    const fs = require('fs');
    const jsonfile = require('jsonfile');
    const validaterRules = require('./validatorRules');
    const promiseHelpers = require('./promiseHelpers');

    let engines;

    const checkerResult = {
        status: 0,
        message: '',
        packages: []
    };

    const packageJsonPath = pathToPackage || path.join(process.cwd(), 'package.json');
    try {
        fs.accessSync(packageJsonPath);
        engines = jsonfile.readFileSync(packageJsonPath).engines;
    }
    catch (ex) {
        checkerResult.message = {
            text: '✘ No package.json found in the current directory so I can\'t validate what you need!',
            type: 'error'
        };
        checkerResult.status = -1;

        return Promise.resolve(checkerResult);
    }

    if (!engines) {
        checkerResult.message = {
            text: '✘ No engines found in package.json so I can\'t validate what you need!',
            type: 'error'
        };
        checkerResult.status = -1;

        return Promise.resolve(checkerResult);
    }

    const thingsToCheck = Object.getOwnPropertyNames(engines);
    const validatorPromises = thingsToCheck.map(validate); // run the function over all items.

    return promiseHelpers.allSettled(validatorPromises)
        .then((inspections) => {
            const environmentIsValid = _.every(inspections,
                (inspection) => inspection.isFulfilled() && inspection.value());

            if (environmentIsValid) {
                checkerResult.message = {
                    text: 'Environment looks good!',
                    type: 'success'
                };
            }
            else {
                checkerResult.message = {
                    text: 'Environment is invalid!',
                    type: 'error'
                };
            }
            return checkerResult;
        });

    function validate(name) {

        // find it in the validators
        const validator = validaterRules[name];

        if (validator === undefined) {
            checkerResult.packages.push({
                name: name,
                validatorFound: false,
                type: 'warn'
            });
            return Promise.resolve(false);
        }

        // call the validator and pass in the version we expect
        return execAndCheck(validator, engines[name]).then((results) => {
            if (results.result) {
                checkerResult.packages.push({
                    name: name,
                    validatorFound: true,
                    expectedVersion: engines[name],
                    foundVersion: engines[name],
                    type: 'success'
                });
            }
            else {
                checkerResult.packages.push({
                    name: name,
                    validatorFound: true,
                    expectedVersion: engines[name],
                    foundVersion: results.reason.trim() || 'missing',
                    type: 'error'
                });
            }

            return Promise.resolve(results.result);
        }).catch((error) => {
            checkerResult.packages.push({
                name: name,
                validatorFound: true,
                expectedVersion: engines[name],
                commandError: error,
                type: 'error'
            });
            return Promise.reject();
        });
    }

    function execAndCheck(validator, expectedVersion) {
        return exec(validator.versionCheck).then((result) => {
            return {
                result: validator.versionValidate(result, expectedVersion),
                reason: result
            };
        }).catch((e) => { throw e; });
    }
};
module.exports = check;

{'fraction_non_alphanumeric': 0.10844734529935986, 'fraction_numerical': 0.0007531065645788879, 'mean_word_length': 1.6176084099868593, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5153705', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1951, 'n_words': 454}