Makefile.js
function getFormatterResults() {
    const stripAnsi = require("strip-ansi");

    const formatterFiles = fs.readdirSync("./lib/formatters/"),
        rules = {
            "no-else-return": "warn",
            indent: ["warn", 4],
            "space-unary-ops": "error",
            semi: ["warn", "always"],
            "consistent-return": "error"
        },
        cli = new CLIEngine({
            useEslintrc: false,
            baseConfig: { extends: "eslint:recommended" },
            rules
        }),
        codeString = [
            "function addOne(i) {",
            "    if (i != NaN) {",
            "        return i ++",
            "    } else {",
            "      return",
            "    }",
            "};"
        ].join("\n"),
        rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true),
        rulesMap = cli.getRules(),
        rulesMeta = {};

    Object.keys(rules).forEach(ruleId => {
        rulesMeta[ruleId] = rulesMap.get(ruleId).meta;
    });

    return formatterFiles.reduce((data, filename) => {
        const fileExt = path.extname(filename),
            name = path.basename(filename, fileExt);

        if (fileExt === ".js") {
            const formattedOutput = cli.getFormatter(name)(
                rawMessages.results,
                { rulesMeta }
            );

            data.formatterResults[name] = {
                result: stripAnsi(formattedOutput)
            };
        }
        return data;
    }, { formatterResults: {} });
}
function getFormatterResults() {
    const stripAnsi = require("strip-ansi");

    const formatterFiles = fs.readdirSync("./lib/formatters/"),
        rules = {
            "no-else-return": "warn",
            indent: ["warn", 4],
            "space-unary-ops": "error",
            semi: ["warn", "always"],
            "consistent-return": "error"
        },
        cli = new CLIEngine({
            useEslintrc: false,
            baseConfig: { extends: "eslint:recommended" },
            rules
        }),
        codeString = [
            "function addOne(i) {",
            "    if (i != NaN) {",
            "        return i ++",
            "    } else {",
            "      return",
            "    }",
            "};"
        ].join("\n"),
        rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true),
        rulesMap = cli.getRules(),
        rulesMeta = {};

    Object.keys(rules).forEach(ruleId => {
        rulesMeta[ruleId] = rulesMap.get(ruleId).meta;
    });

    return formatterFiles.reduce((data, filename) => {
        const fileExt = path.extname(filename),
            name = path.basename(filename, fileExt);

        if (fileExt === ".js") {
            const formattedOutput = cli.getFormatter(name)(
                rawMessages.results,
                { rulesMeta }
            );

            data.formatterResults[name] = {
                result: stripAnsi(formattedOutput)
            };
        }
        return data;
    }, { formatterResults: {} });
}
function getFormatterResults ( ) { const stripAnsi = require ( "strip-ansi" ) ; const formatterFiles = fs . readdirSync ( "./lib/formatters/" ) , rules = { "no-else-return" : "warn" , indent : [ "warn" , 4 ] , "space-unary-ops" : "error" , semi : [ "warn" , "always" ] , "consistent-return" : "error" } , cli = new CLIEngine ( { useEslintrc : false , baseConfig : { extends : "eslint:recommended" } , rules } ) , codeString = [ "function addOne(i) {" , "    if (i != NaN) {" , "        return i ++" , "    } else {" , "      return" , "    }" , "};" ] . join ( "\n" ) , rawMessages = cli . executeOnText ( codeString , "fullOfProblems.js" , true ) , rulesMap = cli . getRules ( ) , rulesMeta = { } ; Object . keys ( rules ) . forEach ( ruleId => { rulesMeta [ ruleId ] = rulesMap . get ( ruleId ) . meta ; } ) ; return formatterFiles . reduce ( ( data , filename ) => { const fileExt = path . extname ( filename ) , name = path . basename ( filename , fileExt ) ; if ( fileExt === ".js" ) { const formattedOutput = cli . getFormatter ( name ) ( rawMessages . results , { rulesMeta } ) ; data . formatterResults [ name ] = { result : stripAnsi ( formattedOutput ) } ; } return data ; } , { formatterResults : { } } ) ; }
Gets linting results from every formatter, based on a hard-coded snippet and config
@returns {Object} Output from each formatter
Gets linting results from every formatter based on a hard - coded snippet and config