path = require("path"),
{ promisify } = require("util"),
{ ESLint } = require("./eslint"),
- { FlatESLint } = require("./eslint/flat-eslint"),
+ { FlatESLint, shouldUseFlatConfig } = require("./eslint/flat-eslint"),
createCLIOptions = require("./options"),
log = require("./shared/logging"),
RuntimeInfo = require("./shared/runtime-info");
const { Legacy: { naming } } = require("@eslint/eslintrc");
-const { findFlatConfigFile } = require("./eslint/flat-eslint");
-const { gitignoreToMinimatch } = require("@humanwhocodes/gitignore-to-minimatch");
const { ModuleImporter } = require("@humanwhocodes/module-importer");
const debug = require("debug")("eslint:cli");
/** @typedef {import("./eslint/eslint").LintMessage} LintMessage */
/** @typedef {import("./eslint/eslint").LintResult} LintResult */
/** @typedef {import("./options").ParsedCLIOptions} ParsedCLIOptions */
+/** @typedef {import("./shared/types").ResultsMeta} ResultsMeta */
//------------------------------------------------------------------------------
// Helpers
overrideConfig[0].plugins = plugins;
}
- if (ignorePattern) {
- overrideConfig.push({
- ignores: ignorePattern.map(gitignoreToMinimatch)
- });
- }
-
} else {
overrideConfigFile = config;
fix: (fix || fixDryRun) && (quiet ? quietFixPredicate : true),
fixTypes: fixType,
ignore,
- ignorePath,
overrideConfig,
overrideConfigFile,
reportUnusedDisableDirectives: reportUnusedDisableDirectives ? "error" : void 0
};
- if (configType !== "flat") {
+ if (configType === "flat") {
+ options.ignorePatterns = ignorePattern;
+ } else {
options.resolvePluginsRelativeTo = resolvePluginsRelativeTo;
options.rulePaths = rulesdir;
options.useEslintrc = eslintrc;
options.extensions = ext;
+ options.ignorePath = ignorePath;
}
return options;
/**
* Count error messages.
* @param {LintResult[]} results The lint results.
- * @returns {{errorCount:number;warningCount:number}} The number of error messages.
+ * @returns {{errorCount:number;fatalErrorCount:number,warningCount:number}} The number of error messages.
*/
function countErrors(results) {
let errorCount = 0;
* @param {LintResult[]} results The results to print.
* @param {string} format The name of the formatter to use or the path to the formatter.
* @param {string} outputFile The path for the output file.
+ * @param {ResultsMeta} resultsMeta Warning count and max threshold.
* @returns {Promise<boolean>} True if the printing succeeds, false if not.
* @private
*/
-async function printResults(engine, results, format, outputFile) {
+async function printResults(engine, results, format, outputFile, resultsMeta) {
let formatter;
try {
return false;
}
- const output = await formatter.format(results);
+ const output = await formatter.format(results, resultsMeta);
if (output) {
if (outputFile) {
* switch to flat config we can remove this logic.
*/
- const usingFlatConfig = allowFlatConfig && !!(await findFlatConfigFile(process.cwd()));
+ const usingFlatConfig = allowFlatConfig && await shouldUseFlatConfig();
debug("Using flat config?", usingFlatConfig);
resultsToPrint = ActiveESLint.getErrorResults(resultsToPrint);
}
- if (await printResults(engine, resultsToPrint, options.format, options.outputFile)) {
+ const resultCounts = countErrors(results);
+ const tooManyWarnings = options.maxWarnings >= 0 && resultCounts.warningCount > options.maxWarnings;
+ const resultsMeta = tooManyWarnings
+ ? {
+ maxWarningsExceeded: {
+ maxWarnings: options.maxWarnings,
+ foundWarnings: resultCounts.warningCount
+ }
+ }
+ : {};
- // Errors and warnings from the original unfiltered results should determine the exit code
- const { errorCount, fatalErrorCount, warningCount } = countErrors(results);
+ if (await printResults(engine, resultsToPrint, options.format, options.outputFile, resultsMeta)) {
- const tooManyWarnings =
- options.maxWarnings >= 0 && warningCount > options.maxWarnings;
+ // Errors and warnings from the original unfiltered results should determine the exit code
const shouldExitForFatalErrors =
- options.exitOnFatalError && fatalErrorCount > 0;
+ options.exitOnFatalError && resultCounts.fatalErrorCount > 0;
- if (!errorCount && tooManyWarnings) {
+ if (!resultCounts.errorCount && tooManyWarnings) {
log.error(
"ESLint found too many warnings (maximum: %s).",
options.maxWarnings
return 2;
}
- return (errorCount || tooManyWarnings) ? 1 : 0;
+ return (resultCounts.errorCount || tooManyWarnings) ? 1 : 0;
}
return 2;