]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/lib/cli.js
import 8.41.0 source
[pve-eslint.git] / eslint / lib / cli.js
index 2fca65c1908b04820ac9d43e877a1bb0d146a55c..a14930e9b0f244ccb333364871e9cd23a90a8fdb 100644 (file)
@@ -19,13 +19,11 @@ const fs = require("fs"),
     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");
@@ -38,6 +36,7 @@ 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
@@ -143,12 +142,6 @@ async function translateOptions({
             overrideConfig[0].plugins = plugins;
         }
 
-        if (ignorePattern) {
-            overrideConfig.push({
-                ignores: ignorePattern.map(gitignoreToMinimatch)
-            });
-        }
-
     } else {
         overrideConfigFile = config;
 
@@ -182,17 +175,19 @@ async function translateOptions({
         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;
@@ -201,7 +196,7 @@ async function translateOptions({
 /**
  * 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;
@@ -239,10 +234,11 @@ async function isDirectory(filePath) {
  * @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 {
@@ -252,7 +248,7 @@ async function printResults(engine, results, format, outputFile) {
         return false;
     }
 
-    const output = await formatter.format(results);
+    const output = await formatter.format(results, resultsMeta);
 
     if (output) {
         if (outputFile) {
@@ -307,7 +303,7 @@ const cli = {
          * 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);
 
@@ -407,17 +403,24 @@ const cli = {
             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
@@ -428,7 +431,7 @@ const cli = {
                 return 2;
             }
 
-            return (errorCount || tooManyWarnings) ? 1 : 0;
+            return (resultCounts.errorCount || tooManyWarnings) ? 1 : 0;
         }
 
         return 2;