Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use ESLINT_USE_FLAT_CONFIG environment variable for flat config #16356

Merged
merged 7 commits into from Oct 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/cli.js
Expand Up @@ -278,6 +278,31 @@ async function printResults(engine, results, format, outputFile) {
return true;
}

/**
* Returns whether flat config should be used.
* @param {boolean} [allowFlatConfig] Whether or not to allow flat config.
* @returns {Promise<boolean>} Where flat config should be used.
*/
async function shouldUseFlatConfig(allowFlatConfig) {
if (!allowFlatConfig) {
return false;
}

switch (process.env.ESLINT_USE_FLAT_CONFIG) {
case "true":
return true;
case "false":
return false;
default:

/*
* If neither explicitly enabled nor disabled, then use the presence
* of a flat config file to determine enablement.
*/
return !!(await findFlatConfigFile(process.cwd()));
}
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -307,7 +332,7 @@ const cli = {
* switch to flat config we can remove this logic.
*/

const usingFlatConfig = allowFlatConfig && !!(await findFlatConfigFile(process.cwd()));
const usingFlatConfig = await shouldUseFlatConfig(allowFlatConfig);

debug("Using flat config?", usingFlatConfig);

Expand Down