@nx/eslint
Version:
54 lines (53 loc) • 2.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.baseEslintConfigFilenames = exports.eslintFlatConfigFilenames = void 0;
exports.getRootESLintFlatConfigFilename = getRootESLintFlatConfigFilename;
exports.useFlatConfig = useFlatConfig;
const semver_1 = require("semver");
exports.eslintFlatConfigFilenames = [
'eslint.config.cjs',
'eslint.config.js',
'eslint.config.mjs',
];
exports.baseEslintConfigFilenames = [
'eslint.base.js',
'eslint.base.config.cjs',
'eslint.base.config.js',
'eslint.base.config.mjs',
];
function getRootESLintFlatConfigFilename(tree) {
for (const file of exports.eslintFlatConfigFilenames) {
if (tree.exists(file)) {
return file;
}
}
throw new Error('Could not find root flat config file');
}
function useFlatConfig(tree) {
// Prioritize taking ESLint's own environment variable into account when determining if we should use flat config
// If it is not defined, then default to true.
if (process.env.ESLINT_USE_FLAT_CONFIG === 'true') {
return true;
}
else if (process.env.ESLINT_USE_FLAT_CONFIG === 'false') {
return false;
}
// If we find an existing flat config file in the root of the provided tree, we should use flat config
if (tree) {
const hasRootFlatConfig = exports.eslintFlatConfigFilenames.some((filename) => tree.exists(filename));
if (hasRootFlatConfig) {
return true;
}
}
// Otherwise fallback to checking the installed eslint version
try {
const { ESLint } = require('eslint');
// Default to any v8 version to compare against in this case as it implies a much older version of ESLint was found (and gte() requires a valid version)
const eslintVersion = ESLint.version || '8.0.0';
return (0, semver_1.gte)(eslintVersion, '9.0.0');
}
catch {
// Default to assuming flat config in case ESLint is not yet installed
return true;
}
}
;