mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +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
|
|
@ -1350,14 +1350,12 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function forRule(rule) {
|
function forRule(rule) {
|
||||||
// Configure rule
|
// Configure rule
|
||||||
var ruleNameFriendly = rule.names[0];
|
var ruleName = rule.names[0].toUpperCase();
|
||||||
var ruleName = ruleNameFriendly.toUpperCase();
|
|
||||||
params.config = effectiveConfig[ruleName];
|
params.config = effectiveConfig[ruleName];
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function throwError(property) {
|
function throwError(property) {
|
||||||
throw new Error("Property '" + property + "' of onError parameter is incorrect.");
|
throw new Error("Property '" + property + "' of onError parameter is incorrect.");
|
||||||
}
|
}
|
||||||
var errors = [];
|
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function onError(errorInfo) {
|
function onError(errorInfo) {
|
||||||
if (!errorInfo ||
|
if (!errorInfo ||
|
||||||
|
|
@ -1366,6 +1364,10 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul
|
||||||
(errorInfo.lineNumber > lines.length)) {
|
(errorInfo.lineNumber > lines.length)) {
|
||||||
throwError("lineNumber");
|
throwError("lineNumber");
|
||||||
}
|
}
|
||||||
|
var lineNumber = errorInfo.lineNumber + frontMatterLines.length;
|
||||||
|
if (!enabledRulesPerLineNumber[lineNumber][ruleName]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (errorInfo.detail &&
|
if (errorInfo.detail &&
|
||||||
!helpers.isString(errorInfo.detail)) {
|
!helpers.isString(errorInfo.detail)) {
|
||||||
throwError("detail");
|
throwError("detail");
|
||||||
|
|
@ -1426,11 +1428,15 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul
|
||||||
cleanFixInfo.insertText = fixInfo.insertText;
|
cleanFixInfo.insertText = fixInfo.insertText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errors.push({
|
results.push({
|
||||||
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
lineNumber: lineNumber,
|
||||||
"detail": errorInfo.detail || null,
|
"ruleName": rule.names[0],
|
||||||
"context": errorInfo.context || null,
|
"ruleNames": rule.names,
|
||||||
"range": errorInfo.range ? __spreadArray([], errorInfo.range) : null,
|
"ruleDescription": rule.description,
|
||||||
|
"ruleInformation": rule.information ? rule.information.href : null,
|
||||||
|
"errorDetail": errorInfo.detail || null,
|
||||||
|
"errorContext": errorInfo.context || null,
|
||||||
|
"errorRange": errorInfo.range ? __spreadArray([], errorInfo.range) : null,
|
||||||
"fixInfo": fixInfo ? cleanFixInfo : null
|
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1449,23 +1455,6 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul
|
||||||
else {
|
else {
|
||||||
rule.function(params, onError);
|
rule.function(params, onError);
|
||||||
}
|
}
|
||||||
// Record any errors (significant performance benefit from length check)
|
|
||||||
if (errors.length > 0) {
|
|
||||||
var filteredErrors = errors
|
|
||||||
.filter(function (error) { return (enabledRulesPerLineNumber[error.lineNumber][ruleName]); })
|
|
||||||
.map(function (error) { return ({
|
|
||||||
"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
|
// Run all rules
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -480,15 +480,13 @@ function lintContent(
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function forRule(rule) {
|
function forRule(rule) {
|
||||||
// Configure rule
|
// Configure rule
|
||||||
const ruleNameFriendly = rule.names[0];
|
const ruleName = rule.names[0].toUpperCase();
|
||||||
const ruleName = ruleNameFriendly.toUpperCase();
|
|
||||||
params.config = effectiveConfig[ruleName];
|
params.config = effectiveConfig[ruleName];
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function throwError(property) {
|
function throwError(property) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Property '" + property + "' of onError parameter is incorrect.");
|
"Property '" + property + "' of onError parameter is incorrect.");
|
||||||
}
|
}
|
||||||
const errors = [];
|
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function onError(errorInfo) {
|
function onError(errorInfo) {
|
||||||
if (!errorInfo ||
|
if (!errorInfo ||
|
||||||
|
|
@ -497,6 +495,10 @@ function lintContent(
|
||||||
(errorInfo.lineNumber > lines.length)) {
|
(errorInfo.lineNumber > lines.length)) {
|
||||||
throwError("lineNumber");
|
throwError("lineNumber");
|
||||||
}
|
}
|
||||||
|
const lineNumber = errorInfo.lineNumber + frontMatterLines.length;
|
||||||
|
if (!enabledRulesPerLineNumber[lineNumber][ruleName]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (errorInfo.detail &&
|
if (errorInfo.detail &&
|
||||||
!helpers.isString(errorInfo.detail)) {
|
!helpers.isString(errorInfo.detail)) {
|
||||||
throwError("detail");
|
throwError("detail");
|
||||||
|
|
@ -557,11 +559,15 @@ function lintContent(
|
||||||
cleanFixInfo.insertText = fixInfo.insertText;
|
cleanFixInfo.insertText = fixInfo.insertText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errors.push({
|
results.push({
|
||||||
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
lineNumber,
|
||||||
"detail": errorInfo.detail || null,
|
"ruleName": rule.names[0],
|
||||||
"context": errorInfo.context || null,
|
"ruleNames": rule.names,
|
||||||
"range": errorInfo.range ? [ ...errorInfo.range ] : null,
|
"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
|
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -578,25 +584,6 @@ function lintContent(
|
||||||
} else {
|
} else {
|
||||||
rule.function(params, onError);
|
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
|
// Run all rules
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue