lib/config/config-file.js
function writeJSConfigFile(config, filePath) {
    debug(`Writing JS config file: ${filePath}`);

    let contentToWrite;
    const stringifiedContent = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })};`;

    try {
        const CLIEngine = require("../cli-engine");
        const linter = new CLIEngine({
            baseConfig: config,
            fix: true,
            useEslintrc: false
        });
        const report = linter.executeOnText(stringifiedContent);

        contentToWrite = report.results[0].output || stringifiedContent;
    } catch (e) {
        debug("Error linting JavaScript config file, writing unlinted version");
        const errorMessage = e.message;

        contentToWrite = stringifiedContent;
        e.message = "An error occurred while generating your JavaScript config file. ";
        e.message += "A config file was still generated, but the config file itself may not follow your linting rules.";
        e.message += `\nError: ${errorMessage}`;
        throw e;
    } finally {
        fs.writeFileSync(filePath, contentToWrite, "utf8");
    }
}
function writeJSConfigFile(config, filePath) {
    debug(`Writing JS config file: ${filePath}`);

    let contentToWrite;
    const stringifiedContent = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })};`;

    try {
        const CLIEngine = require("../cli-engine");
        const linter = new CLIEngine({
            baseConfig: config,
            fix: true,
            useEslintrc: false
        });
        const report = linter.executeOnText(stringifiedContent);

        contentToWrite = report.results[0].output || stringifiedContent;
    } catch (e) {
        debug("Error linting JavaScript config file, writing unlinted version");
        const errorMessage = e.message;

        contentToWrite = stringifiedContent;
        e.message = "An error occurred while generating your JavaScript config file. ";
        e.message += "A config file was still generated, but the config file itself may not follow your linting rules.";
        e.message += `\nError: ${errorMessage}`;
        throw e;
    } finally {
        fs.writeFileSync(filePath, contentToWrite, "utf8");
    }
}
function writeJSConfigFile ( config , filePath ) { debug ( ` ${ filePath } ` ) ; let contentToWrite ; const stringifiedContent = ` ${ stringify ( config , { cmp : sortByKey , space : 4 } ) } ` ; try { const CLIEngine = require ( "../cli-engine" ) ; const linter = new CLIEngine ( { baseConfig : config , fix : true , useEslintrc : false } ) ; const report = linter . executeOnText ( stringifiedContent ) ; contentToWrite = report . results [ 0 ] . output || stringifiedContent ; } catch ( e ) { debug ( "Error linting JavaScript config file, writing unlinted version" ) ; const errorMessage = e . message ; contentToWrite = stringifiedContent ; e . message = "An error occurred while generating your JavaScript config file. " ; e . message += "A config file was still generated, but the config file itself may not follow your linting rules." ; e . message += ` \n ${ errorMessage } ` ; throw e ; } finally { fs . writeFileSync ( filePath , contentToWrite , "utf8" ) ; } }
Writes a configuration file in JavaScript format.
@param {Object} config The configuration object to write.
@param {string} filePath The filename to write to.
@throws {Error} If an error occurs linting the config file contents.
@returns {void}
@private
Writes a configuration file in JavaScript format .