mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add validation of onError callback object for rules.
This commit is contained in:
parent
802c81f929
commit
7a752784f1
7 changed files with 107 additions and 12 deletions
|
|
@ -324,8 +324,36 @@ function lintContent(
|
|||
var ruleNameFriendly = rule.names[0];
|
||||
var ruleName = ruleNameFriendly.toUpperCase();
|
||||
params.config = effectiveConfig[ruleName];
|
||||
function throwError(property) {
|
||||
throw new Error(
|
||||
"Property '" + property + "' of onError parameter is incorrect.");
|
||||
}
|
||||
var errors = [];
|
||||
function onError(errorInfo) {
|
||||
if (!errorInfo ||
|
||||
!errorInfo.lineNumber ||
|
||||
!shared.isNumber(errorInfo.lineNumber)) {
|
||||
throwError("lineNumber");
|
||||
}
|
||||
if ((errorInfo.detail !== null) &&
|
||||
(errorInfo.detail !== undefined) &&
|
||||
(!shared.isString(errorInfo.detail) ||
|
||||
shared.isEmptyString(errorInfo.detail))) {
|
||||
throwError("detail");
|
||||
}
|
||||
if ((errorInfo.context !== null) &&
|
||||
(errorInfo.context !== undefined) &&
|
||||
(!shared.isString(errorInfo.context) ||
|
||||
shared.isEmptyString(errorInfo.context))) {
|
||||
throwError("context");
|
||||
}
|
||||
if (errorInfo.range &&
|
||||
(!Array.isArray(errorInfo.range) ||
|
||||
(errorInfo.range.length !== 2) ||
|
||||
!shared.isNumber(errorInfo.range[0]) ||
|
||||
!shared.isNumber(errorInfo.range[1]))) {
|
||||
throwError("range");
|
||||
}
|
||||
errors.push({
|
||||
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
||||
"detail": errorInfo.detail || null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue