mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update fixInfo.lineNumber for front matter, sanitize fixInfo object from rules.
This commit is contained in:
parent
377323d872
commit
9202ebe390
5 changed files with 137 additions and 21 deletions
|
|
@ -392,34 +392,44 @@ function lintContent(
|
|||
throwError("range");
|
||||
}
|
||||
const fixInfo = errorInfo.fixInfo;
|
||||
const cleanFixInfo = {};
|
||||
if (fixInfo) {
|
||||
if (!helpers.isObject(fixInfo)) {
|
||||
throwError("fixInfo");
|
||||
}
|
||||
if ((fixInfo.lineNumber !== undefined) &&
|
||||
(!helpers.isNumber(fixInfo.lineNumber) ||
|
||||
(fixInfo.lineNumber < 1) ||
|
||||
(fixInfo.lineNumber > lines.length))) {
|
||||
throwError("fixInfo.lineNumber");
|
||||
if (fixInfo.lineNumber !== undefined) {
|
||||
if ((!helpers.isNumber(fixInfo.lineNumber) ||
|
||||
(fixInfo.lineNumber < 1) ||
|
||||
(fixInfo.lineNumber > lines.length))) {
|
||||
throwError("fixInfo.lineNumber");
|
||||
}
|
||||
cleanFixInfo.lineNumber =
|
||||
fixInfo.lineNumber + frontMatterLines.length;
|
||||
}
|
||||
const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber;
|
||||
if ((fixInfo.editColumn !== undefined) &&
|
||||
(!helpers.isNumber(fixInfo.editColumn) ||
|
||||
(fixInfo.editColumn < 1) ||
|
||||
(fixInfo.editColumn >
|
||||
lines[effectiveLineNumber - 1].length + 1))) {
|
||||
throwError("fixInfo.editColumn");
|
||||
if (fixInfo.editColumn !== undefined) {
|
||||
if ((!helpers.isNumber(fixInfo.editColumn) ||
|
||||
(fixInfo.editColumn < 1) ||
|
||||
(fixInfo.editColumn >
|
||||
lines[effectiveLineNumber - 1].length + 1))) {
|
||||
throwError("fixInfo.editColumn");
|
||||
}
|
||||
cleanFixInfo.editColumn = fixInfo.editColumn;
|
||||
}
|
||||
if ((fixInfo.deleteCount !== undefined) &&
|
||||
(!helpers.isNumber(fixInfo.deleteCount) ||
|
||||
(fixInfo.deleteCount < -1) ||
|
||||
(fixInfo.deleteCount >
|
||||
lines[effectiveLineNumber - 1].length))) {
|
||||
throwError("fixInfo.deleteCount");
|
||||
if (fixInfo.deleteCount !== undefined) {
|
||||
if ((!helpers.isNumber(fixInfo.deleteCount) ||
|
||||
(fixInfo.deleteCount < -1) ||
|
||||
(fixInfo.deleteCount >
|
||||
lines[effectiveLineNumber - 1].length))) {
|
||||
throwError("fixInfo.deleteCount");
|
||||
}
|
||||
cleanFixInfo.deleteCount = fixInfo.deleteCount;
|
||||
}
|
||||
if ((fixInfo.insertText !== undefined) &&
|
||||
!helpers.isString(fixInfo.insertText)) {
|
||||
throwError("fixInfo.insertText");
|
||||
if (fixInfo.insertText !== undefined) {
|
||||
if (!helpers.isString(fixInfo.insertText)) {
|
||||
throwError("fixInfo.insertText");
|
||||
}
|
||||
cleanFixInfo.insertText = fixInfo.insertText;
|
||||
}
|
||||
}
|
||||
errors.push({
|
||||
|
|
@ -427,7 +437,7 @@ function lintContent(
|
|||
"detail": errorInfo.detail || null,
|
||||
"context": errorInfo.context || null,
|
||||
"range": errorInfo.range || null,
|
||||
"fixInfo": errorInfo.fixInfo || null
|
||||
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||
});
|
||||
}
|
||||
// Call (possibly external) rule function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue