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
docs: disambiguate types FormatterFunction
and LoadedFormatter
#15727
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -56,6 +56,8 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]); | |||||||
/** @typedef {import("../shared/types").Plugin} Plugin */ | ||||||||
/** @typedef {import("../shared/types").RuleConf} RuleConf */ | ||||||||
/** @typedef {import("../shared/types").Rule} Rule */ | ||||||||
/** @typedef {import("../shared/types").LintResult} LintResult */ | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this file, there is already a definition for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @mdjermanovic, I missed that one! The definition of Lines 408 to 410 in 5d60812
The other definition could be better modeled with type inheritance, but changing it would be outside the scope of this PR, I think. I will remove the import if nobody comes up with a different suggestion. |
||||||||
/** @typedef {import("../shared/types").FormatterFunction} FormatterFunction */ | ||||||||
/** @typedef {ReturnType<CascadingConfigArrayFactory.getConfigArrayForFile>} ConfigArray */ | ||||||||
/** @typedef {ReturnType<ConfigArray.extractConfig>} ExtractedConfig */ | ||||||||
|
||||||||
|
@@ -1002,7 +1004,7 @@ class CLIEngine { | |||||||
* @param {string} [format] The name of the format to load or the path to a | ||||||||
* custom formatter. | ||||||||
* @throws {any} As may be thrown by requiring of formatter | ||||||||
* @returns {(Function|null)} The formatter function or null if the `format` is not a string. | ||||||||
* @returns {(FormatterFunction|null)} The formatter function or null if the `format` is not a string. | ||||||||
*/ | ||||||||
getFormatter(format) { | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -173,3 +173,27 @@ module.exports = {}; | |||||||
* @property {string} ruleId The rule ID. | ||||||||
* @property {string[]} replacedBy The rule IDs that replace this deprecated rule. | ||||||||
*/ | ||||||||
|
||||||||
/** | ||||||||
* A linting result. | ||||||||
* @typedef {Object} LintResult | ||||||||
* @property {string} filePath The path to the file that was linted. | ||||||||
* @property {LintMessage[]} messages All of the messages for the result. | ||||||||
* @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result. | ||||||||
* @property {number} errorCount Number of errors for the result. | ||||||||
* @property {number} fatalErrorCount Number of fatal errors for the result. | ||||||||
* @property {number} warningCount Number of warnings for the result. | ||||||||
* @property {number} fixableErrorCount Number of fixable errors for the result. | ||||||||
* @property {number} fixableWarningCount Number of fixable warnings for the result. | ||||||||
* @property {string} [source] The source code of the file that was linted. | ||||||||
* @property {string} [output] The source code of the file that was linted, with as many fixes applied as possible. | ||||||||
* @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules. | ||||||||
*/ | ||||||||
|
||||||||
/** | ||||||||
* A formatter function. | ||||||||
* @callback FormatterFunction | ||||||||
* @param {LintResult[]} results The list of linting results. | ||||||||
* @param {{cwd: string, rulesMeta: Record<string, RuleMeta>}} [context] A context object. If the formatter is used with the legacy API, this argument may be unspecified or have a different value. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think a note about different APIs isn't necessary, as it could be added to basically any type we have. For example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I included that note because it is mentioned in the developer guide:
So the legacy environments are not those using old ESLint versions, but those that use the deprecated |
||||||||
* @returns {string | Promise<string>} Formatted text. | ||||||||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure this change makes sense. The variable name doesn’t need to match the type name.