function configureRules(answers, config) {
    const BAR_TOTAL = 20,
        BAR_SOURCE_CODE_TOTAL = 4,
        newConfig = Object.assign({}, config),
        disabledConfigs = {};
    let sourceCodes,
        registry;

    // Set up a progress bar, as this process can take a long time
    const bar = new ProgressBar("Determining Config: :percent [:bar] :elapseds elapsed, eta :etas ", {
        width: 30,
        total: BAR_TOTAL
    });

    bar.tick(0); // Shows the progress bar

    // Get the SourceCode of all chosen files
    const patterns = answers.patterns.split(/[\s]+/u);

    try {
        sourceCodes = getSourceCodeOfFiles(patterns, { baseConfig: newConfig, useEslintrc: false }, total => {
            bar.tick((BAR_SOURCE_CODE_TOTAL / total));
        });
    } catch (e) {
        log.info("\n");
        throw e;
    }
    const fileQty = Object.keys(sourceCodes).length;

    if (fileQty === 0) {
        log.info("\n");
        throw new Error("Automatic Configuration failed.  No files were able to be parsed.");
    }

    // Create a registry of rule configs
    registry = new autoconfig.Registry();
    registry.populateFromCoreRules();

    // Lint all files with each rule config in the registry
    registry = registry.lintSourceCode(sourceCodes, newConfig, total => {
        bar.tick((BAR_TOTAL - BAR_SOURCE_CODE_TOTAL) / total); // Subtract out ticks used at beginning
    });
    debug(`\nRegistry: ${util.inspect(registry.rules, { depth: null })}`);

    // Create a list of recommended rules, because we don't want to disable them
    const recRules = Object.keys(recConfig.rules).filter(ruleId => ConfigOps.isErrorSeverity(recConfig.rules[ruleId]));

    // Find and disable rules which had no error-free configuration
    const failingRegistry = registry.getFailingRulesRegistry();

    Object.keys(failingRegistry.rules).forEach(ruleId => {

        // If the rule is recommended, set it to error, otherwise disable it
        disabledConfigs[ruleId] = (recRules.indexOf(ruleId) !== -1) ? 2 : 0;
    });

    // Now that we know which rules to disable, strip out configs with errors
    registry = registry.stripFailingConfigs();

    /*
     * If there is only one config that results in no errors for a rule, we should use it.
     * createConfig will only add rules that have one configuration in the registry.
     */
    const singleConfigs = registry.createConfig().rules;

    /*
     * The "sweet spot" for number of options in a config seems to be two (severity plus one option).
     * Very often, a third option (usually an object) is available to address
     * edge cases, exceptions, or unique situations. We will prefer to use a config with
     * specificity of two.
     */
    const specTwoConfigs = registry.filterBySpecificity(2).createConfig().rules;

    // Maybe a specific combination using all three options works
    const specThreeConfigs = registry.filterBySpecificity(3).createConfig().rules;

    // If all else fails, try to use the default (severity only)
    const defaultConfigs = registry.filterBySpecificity(1).createConfig().rules;

    // Combine configs in reverse priority order (later take precedence)
    newConfig.rules = Object.assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs);

    // Make sure progress bar has finished (floating point rounding)
    bar.update(BAR_TOTAL);

    // Log out some stats to let the user know what happened
    const finalRuleIds = Object.keys(newConfig.rules);
    const totalRules = finalRuleIds.length;
    const enabledRules = finalRuleIds.filter(ruleId => (newConfig.rules[ruleId] !== 0)).length;
    const resultMessage = [
        `\nEnabled ${enabledRules} out of ${totalRules}`,
        `rules based on ${fileQty}`,
        `file${(fileQty === 1) ? "." : "s."}`
    ].join(" ");

    log.info(resultMessage);

    ConfigOps.normalizeToStrings(newConfig);
    return newConfig;
}
function configureRules(answers, config) {
    const BAR_TOTAL = 20,
        BAR_SOURCE_CODE_TOTAL = 4,
        newConfig = Object.assign({}, config),
        disabledConfigs = {};
    let sourceCodes,
        registry;

    // Set up a progress bar, as this process can take a long time
    const bar = new ProgressBar("Determining Config: :percent [:bar] :elapseds elapsed, eta :etas ", {
        width: 30,
        total: BAR_TOTAL
    });

    bar.tick(0); // Shows the progress bar

    // Get the SourceCode of all chosen files
    const patterns = answers.patterns.split(/[\s]+/u);

    try {
        sourceCodes = getSourceCodeOfFiles(patterns, { baseConfig: newConfig, useEslintrc: false }, total => {
            bar.tick((BAR_SOURCE_CODE_TOTAL / total));
        });
    } catch (e) {
        log.info("\n");
        throw e;
    }
    const fileQty = Object.keys(sourceCodes).length;

    if (fileQty === 0) {
        log.info("\n");
        throw new Error("Automatic Configuration failed.  No files were able to be parsed.");
    }

    // Create a registry of rule configs
    registry = new autoconfig.Registry();
    registry.populateFromCoreRules();

    // Lint all files with each rule config in the registry
    registry = registry.lintSourceCode(sourceCodes, newConfig, total => {
        bar.tick((BAR_TOTAL - BAR_SOURCE_CODE_TOTAL) / total); // Subtract out ticks used at beginning
    });
    debug(`\nRegistry: ${util.inspect(registry.rules, { depth: null })}`);

    // Create a list of recommended rules, because we don't want to disable them
    const recRules = Object.keys(recConfig.rules).filter(ruleId => ConfigOps.isErrorSeverity(recConfig.rules[ruleId]));

    // Find and disable rules which had no error-free configuration
    const failingRegistry = registry.getFailingRulesRegistry();

    Object.keys(failingRegistry.rules).forEach(ruleId => {

        // If the rule is recommended, set it to error, otherwise disable it
        disabledConfigs[ruleId] = (recRules.indexOf(ruleId) !== -1) ? 2 : 0;
    });

    // Now that we know which rules to disable, strip out configs with errors
    registry = registry.stripFailingConfigs();

    /*
     * If there is only one config that results in no errors for a rule, we should use it.
     * createConfig will only add rules that have one configuration in the registry.
     */
    const singleConfigs = registry.createConfig().rules;

    /*
     * The "sweet spot" for number of options in a config seems to be two (severity plus one option).
     * Very often, a third option (usually an object) is available to address
     * edge cases, exceptions, or unique situations. We will prefer to use a config with
     * specificity of two.
     */
    const specTwoConfigs = registry.filterBySpecificity(2).createConfig().rules;

    // Maybe a specific combination using all three options works
    const specThreeConfigs = registry.filterBySpecificity(3).createConfig().rules;

    // If all else fails, try to use the default (severity only)
    const defaultConfigs = registry.filterBySpecificity(1).createConfig().rules;

    // Combine configs in reverse priority order (later take precedence)
    newConfig.rules = Object.assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs);

    // Make sure progress bar has finished (floating point rounding)
    bar.update(BAR_TOTAL);

    // Log out some stats to let the user know what happened
    const finalRuleIds = Object.keys(newConfig.rules);
    const totalRules = finalRuleIds.length;
    const enabledRules = finalRuleIds.filter(ruleId => (newConfig.rules[ruleId] !== 0)).length;
    const resultMessage = [
        `\nEnabled ${enabledRules} out of ${totalRules}`,
        `rules based on ${fileQty}`,
        `file${(fileQty === 1) ? "." : "s."}`
    ].join(" ");

    log.info(resultMessage);

    ConfigOps.normalizeToStrings(newConfig);
    return newConfig;
}
function configureRules ( answers , config ) { const BAR_TOTAL = 20 , BAR_SOURCE_CODE_TOTAL = 4 , newConfig = Object . assign ( { } , config ) , disabledConfigs = { } ; let sourceCodes , registry ; // Set up a progress bar, as this process can take a long time const bar = new ProgressBar ( "Determining Config: :percent [:bar] :elapseds elapsed, eta :etas " , { width : 30 , total : BAR_TOTAL } ) ; bar . tick ( 0 ) ; // Shows the progress bar // Get the SourceCode of all chosen files const patterns = answers . patterns . split ( / [\s]+ / u ) ; try { sourceCodes = getSourceCodeOfFiles ( patterns , { baseConfig : newConfig , useEslintrc : false } , total => { bar . tick ( ( BAR_SOURCE_CODE_TOTAL / total ) ) ; } ) ; } catch ( e ) { log . info ( "\n" ) ; throw e ; } const fileQty = Object . keys ( sourceCodes ) . length ; if ( fileQty === 0 ) { log . info ( "\n" ) ; throw new Error ( "Automatic Configuration failed.  No files were able to be parsed." ) ; } // Create a registry of rule configs registry = new autoconfig . Registry ( ) ; registry . populateFromCoreRules ( ) ; // Lint all files with each rule config in the registry registry = registry . lintSourceCode ( sourceCodes , newConfig , total => { bar . tick ( ( BAR_TOTAL - BAR_SOURCE_CODE_TOTAL ) / total ) ; // Subtract out ticks used at beginning } ) ; debug ( ` \n ${ util . inspect ( registry . rules , { depth : null } ) } ` ) ; // Create a list of recommended rules, because we don't want to disable them const recRules = Object . keys ( recConfig . rules ) . filter ( ruleId => ConfigOps . isErrorSeverity ( recConfig . rules [ ruleId ] ) ) ; // Find and disable rules which had no error-free configuration const failingRegistry = registry . getFailingRulesRegistry ( ) ; Object . keys ( failingRegistry . rules ) . forEach ( ruleId => { // If the rule is recommended, set it to error, otherwise disable it disabledConfigs [ ruleId ] = ( recRules . indexOf ( ruleId ) !== - 1 ) ? 2 : 0 ; } ) ; // Now that we know which rules to disable, strip out configs with errors registry = registry . stripFailingConfigs ( ) ; /*
     * If there is only one config that results in no errors for a rule, we should use it.
     * createConfig will only add rules that have one configuration in the registry.
     */ const singleConfigs = registry . createConfig ( ) . rules ; /*
     * The "sweet spot" for number of options in a config seems to be two (severity plus one option).
     * Very often, a third option (usually an object) is available to address
     * edge cases, exceptions, or unique situations. We will prefer to use a config with
     * specificity of two.
     */ const specTwoConfigs = registry . filterBySpecificity ( 2 ) . createConfig ( ) . rules ; // Maybe a specific combination using all three options works const specThreeConfigs = registry . filterBySpecificity ( 3 ) . createConfig ( ) . rules ; // If all else fails, try to use the default (severity only) const defaultConfigs = registry . filterBySpecificity ( 1 ) . createConfig ( ) . rules ; // Combine configs in reverse priority order (later take precedence) newConfig . rules = Object . assign ( { } , disabledConfigs , defaultConfigs , specThreeConfigs , specTwoConfigs , singleConfigs ) ; // Make sure progress bar has finished (floating point rounding) bar . update ( BAR_TOTAL ) ; // Log out some stats to let the user know what happened const finalRuleIds = Object . keys ( newConfig . rules ) ; const totalRules = finalRuleIds . length ; const enabledRules = finalRuleIds . filter ( ruleId => ( newConfig . rules [ ruleId ] !== 0 ) ) . length ; const resultMessage = [ ` \n ${ enabledRules } ${ totalRules } ` , ` ${ fileQty } ` , ` ${ ( fileQty === 1 ) ? "." : "s." } ` ] . join ( " " ) ; log . info ( resultMessage ) ; ConfigOps . normalizeToStrings ( newConfig ) ; return newConfig ; }
Set the `rules` of a config by examining a user's source code

Note: This clones the config object and returns a new config to avoid mutating
the original config parameter.

@param   {Object} answers  answers received from inquirer
@param   {Object} config   config object
@returns {Object}          config object with configured rules
Set the rules of a config by examining a user s source code
Configure the rules of the given file