Allow a custom rule's onError implementation to override that rule's information URL for each error.

This commit is contained in:
David Anson 2023-07-11 21:44:45 -07:00
parent 14974e52a9
commit c699b8e22b
7 changed files with 235 additions and 18 deletions

View file

@ -218,6 +218,10 @@ type RuleOnErrorInfo = {
* Context for the error.
*/
context?: string;
/**
* Link to more information.
*/
information?: URL;
/**
* Column number (1-based) and length.
*/

View file

@ -59,7 +59,7 @@ function validateRuleList(ruleList, synchronous) {
if (
!result &&
rule.information &&
(Object.getPrototypeOf(rule.information) !== URL.prototype)
!helpers.isUrl(rule.information)
) {
result = newError("information");
}
@ -629,6 +629,10 @@ function lintContent(
!helpers.isString(errorInfo.context)) {
throwError("context");
}
if (errorInfo.information &&
!helpers.isUrl(errorInfo.information)) {
throwError("information");
}
if (errorInfo.range &&
(!Array.isArray(errorInfo.range) ||
(errorInfo.range.length !== 2) ||
@ -681,12 +685,13 @@ function lintContent(
cleanFixInfo.insertText = fixInfo.insertText;
}
}
const information = errorInfo.information || rule.information;
results.push({
lineNumber,
"ruleName": rule.names[0],
"ruleNames": rule.names,
"ruleDescription": rule.description,
"ruleInformation": rule.information ? rule.information.href : null,
"ruleInformation": information ? information.href : null,
"errorDetail": errorInfo.detail || null,
"errorContext": errorInfo.context || null,
"errorRange": errorInfo.range ? [ ...errorInfo.range ] : null,
@ -1314,6 +1319,7 @@ module.exports = markdownlint;
* @property {number} lineNumber Line number (1-based).
* @property {string} [detail] Detail about the error.
* @property {string} [context] Context for the error.
* @property {URL} [information] Link to more information.
* @property {number[]} [range] Column number (1-based) and length.
* @property {RuleOnErrorFixInfo} [fixInfo] Fix information.
*/