mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Simplify lintContent by removing errors array and processing errors in onError so nothing needs to be done after invoking a rule.
This commit is contained in:
parent
d3c56d3ab8
commit
e7662b11b5
2 changed files with 28 additions and 52 deletions
|
|
@ -480,15 +480,13 @@ function lintContent(
|
|||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function forRule(rule) {
|
||||
// Configure rule
|
||||
const ruleNameFriendly = rule.names[0];
|
||||
const ruleName = ruleNameFriendly.toUpperCase();
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
params.config = effectiveConfig[ruleName];
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function throwError(property) {
|
||||
throw new Error(
|
||||
"Property '" + property + "' of onError parameter is incorrect.");
|
||||
}
|
||||
const errors = [];
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
function onError(errorInfo) {
|
||||
if (!errorInfo ||
|
||||
|
|
@ -497,6 +495,10 @@ function lintContent(
|
|||
(errorInfo.lineNumber > lines.length)) {
|
||||
throwError("lineNumber");
|
||||
}
|
||||
const lineNumber = errorInfo.lineNumber + frontMatterLines.length;
|
||||
if (!enabledRulesPerLineNumber[lineNumber][ruleName]) {
|
||||
return;
|
||||
}
|
||||
if (errorInfo.detail &&
|
||||
!helpers.isString(errorInfo.detail)) {
|
||||
throwError("detail");
|
||||
|
|
@ -557,11 +559,15 @@ function lintContent(
|
|||
cleanFixInfo.insertText = fixInfo.insertText;
|
||||
}
|
||||
}
|
||||
errors.push({
|
||||
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
||||
"detail": errorInfo.detail || null,
|
||||
"context": errorInfo.context || null,
|
||||
"range": errorInfo.range ? [ ...errorInfo.range ] : null,
|
||||
results.push({
|
||||
lineNumber,
|
||||
"ruleName": rule.names[0],
|
||||
"ruleNames": rule.names,
|
||||
"ruleDescription": rule.description,
|
||||
"ruleInformation": rule.information ? rule.information.href : null,
|
||||
"errorDetail": errorInfo.detail || null,
|
||||
"errorContext": errorInfo.context || null,
|
||||
"errorRange": errorInfo.range ? [ ...errorInfo.range ] : null,
|
||||
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||
});
|
||||
}
|
||||
|
|
@ -578,25 +584,6 @@ function lintContent(
|
|||
} else {
|
||||
rule.function(params, onError);
|
||||
}
|
||||
// Record any errors (significant performance benefit from length check)
|
||||
if (errors.length > 0) {
|
||||
const filteredErrors = errors
|
||||
.filter((error) => (
|
||||
enabledRulesPerLineNumber[error.lineNumber][ruleName]
|
||||
))
|
||||
.map((error) => ({
|
||||
"lineNumber": error.lineNumber,
|
||||
"ruleName": rule.names[0],
|
||||
"ruleNames": rule.names,
|
||||
"ruleDescription": rule.description,
|
||||
"ruleInformation": rule.information ? rule.information.href : null,
|
||||
"errorDetail": error.detail,
|
||||
"errorContext": error.context,
|
||||
"errorRange": error.range,
|
||||
"fixInfo": error.fixInfo
|
||||
}));
|
||||
Array.prototype.push.apply(results, filteredErrors);
|
||||
}
|
||||
}
|
||||
// Run all rules
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue