diff --git a/docs/src/developer-guide/nodejs-api.md b/docs/src/developer-guide/nodejs-api.md index 0b8d84226b4..eb286c7bfff 100644 --- a/docs/src/developer-guide/nodejs-api.md +++ b/docs/src/developer-guide/nodejs-api.md @@ -410,8 +410,8 @@ This edit information means replacing the range of the `range` property by the ` The `LoadedFormatter` value is the object to convert the [LintResult] objects to text. The [eslint.loadFormatter()][eslint-loadformatter] method returns it. It has the following method: -* `format` (`(results: LintResult[]) => string | Promise`)
- The method to convert the [LintResult] objects to text. +* `format` (`(results: LintResult[], resultsMeta: ResultsMeta) => string | Promise`)
+ The method to convert the [LintResult] objects to text. `resultsMeta` is an object that will contain a `maxWarningsExceeded` object if `--max-warnings` was set and the number of warnings exceeded the limit. The `maxWarningsExceeded` object will contain two properties: `maxWarnings`, the value of the `--max-warnings` option, and `foundWarnings`, the number of lint warnings. --- diff --git a/lib/cli.js b/lib/cli.js index 93ee2a8be48..58c50f7c2bd 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -38,6 +38,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 @@ -239,7 +240,7 @@ 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 {Object} resultsMeta Warning count and max threshold. + * @param {ResultsMeta} resultsMeta Warning count and max threshold. * @returns {Promise} True if the printing succeeds, false if not. * @private */ diff --git a/lib/eslint/eslint.js b/lib/eslint/eslint.js index 3b8d4a956dc..e1d2116944e 100644 --- a/lib/eslint/eslint.js +++ b/lib/eslint/eslint.js @@ -36,11 +36,12 @@ const { version } = require("../../package.json"); /** @typedef {import("../shared/types").Plugin} Plugin */ /** @typedef {import("../shared/types").Rule} Rule */ /** @typedef {import("../shared/types").LintResult} LintResult */ +/** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */ /** * The main formatter object. * @typedef LoadedFormatter - * @property {function(LintResult[]): string | Promise} format format function. + * @property {(results: LintResult[], resultsMeta: ResultsMeta) => string | Promise} format format function. */ /** @@ -625,7 +626,7 @@ class ESLint { /** * The main formatter method. * @param {LintResult[]} results The lint results to format. - * @param {Object} resultsMeta Warning count and max threshold. + * @param {ResultsMeta} resultsMeta Warning count and max threshold. * @returns {string | Promise} The formatted lint results. */ format(results, resultsMeta) { diff --git a/lib/eslint/flat-eslint.js b/lib/eslint/flat-eslint.js index 0886979e88c..5cec9807149 100644 --- a/lib/eslint/flat-eslint.js +++ b/lib/eslint/flat-eslint.js @@ -59,6 +59,7 @@ const LintResultCache = require("../cli-engine/lint-result-cache"); /** @typedef {import("../shared/types").LintMessage} LintMessage */ /** @typedef {import("../shared/types").ParserOptions} ParserOptions */ /** @typedef {import("../shared/types").Plugin} Plugin */ +/** @typedef {import("../shared/types").ResultsMeta} ResultsMeta */ /** @typedef {import("../shared/types").RuleConf} RuleConf */ /** @typedef {import("../shared/types").Rule} Rule */ /** @typedef {ReturnType} ExtractedConfig */ @@ -1114,7 +1115,7 @@ class FlatESLint { /** * The main formatter method. * @param {LintResults[]} results The lint results to format. - * @param {Object} resultsMeta Warning count and max threshold. + * @param {ResultsMeta} resultsMeta Warning count and max threshold. * @returns {string} The formatted lint results. */ format(results, resultsMeta) { diff --git a/lib/shared/types.js b/lib/shared/types.js index 60f9f1d6afe..20335f68a73 100644 --- a/lib/shared/types.js +++ b/lib/shared/types.js @@ -190,10 +190,23 @@ module.exports = {}; * @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules. */ +/** + * Information provided when the maximum warning threshold is exceeded. + * @typedef {Object} MaxWarningsExceeded + * @property {number} maxWarnings Number of warnings to trigger nonzero exit code. + * @property {number} foundWarnings Number of warnings found while linting. + */ + +/** + * Metadata about results for formatters. + * @typedef {Object} ResultsMeta + * @property {MaxWarningsExceeded} [maxWarningsExceeded] Present if the maxWarnings threshold was exceeded. + */ + /** * A formatter function. * @callback FormatterFunction * @param {LintResult[]} results The list of linting results. - * @param {{cwd: string, rulesMeta: Record}} [context] A context object. + * @param {{cwd: string, maxWarningsExceeded?: MaxWarningsExceeded, rulesMeta: Record}} [context] A context object. * @returns {string | Promise} Formatted text. */