mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Move error reporting helpers out of core to simplify API for rule.func.
This commit is contained in:
parent
6319cbba3e
commit
25b6e6f2f3
2 changed files with 148 additions and 136 deletions
|
|
@ -232,50 +232,15 @@ function lintContent(
|
|||
var ruleName = rule.names[0];
|
||||
params.options = mergedRules[ruleName];
|
||||
var errors = [];
|
||||
function addError(lineNumber, detail, context, range) {
|
||||
function onError(errorInfo) {
|
||||
errors.push({
|
||||
"lineNumber": lineNumber + frontMatterLines.length,
|
||||
"detail": detail || null,
|
||||
"context": context || null,
|
||||
"range": range || null
|
||||
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
||||
"detail": errorInfo.detail || null,
|
||||
"context": errorInfo.context || null,
|
||||
"range": errorInfo.range || null
|
||||
});
|
||||
}
|
||||
var errorHelpers = {
|
||||
"add": function add(lineNumber) {
|
||||
addError(lineNumber);
|
||||
},
|
||||
"addDetail": function addDetail(lineNumber, detail) {
|
||||
addError(lineNumber, detail);
|
||||
},
|
||||
"addDetailIf":
|
||||
function addDetailIf(lineNumber, expected, actual, detail, range) {
|
||||
if (expected !== actual) {
|
||||
addError(
|
||||
lineNumber,
|
||||
"Expected: " + expected + "; Actual: " + actual +
|
||||
(detail ? "; " + detail : ""),
|
||||
null,
|
||||
range);
|
||||
}
|
||||
},
|
||||
"addContext":
|
||||
function addContext(lineNumber, context, left, right, range) {
|
||||
if (context.length <= 30) {
|
||||
// Nothing to do
|
||||
} else if (left && right) {
|
||||
context = context.substr(0, 15) + "..." + context.substr(-15);
|
||||
} else if (right) {
|
||||
context = "..." + context.substr(-30);
|
||||
} else {
|
||||
context = context.substr(0, 30) + "...";
|
||||
}
|
||||
addError(lineNumber, null, context, range);
|
||||
},
|
||||
"count": function count() {
|
||||
return errors.length;
|
||||
}
|
||||
};
|
||||
rule.func(params, errorHelpers);
|
||||
rule.func(params, onError);
|
||||
// Record any errors (significant performance benefit from length check)
|
||||
if (errors.length) {
|
||||
errors.sort(lineNumberComparison);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue