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");
|
throwError("range");
|
||||||
}
|
}
|
||||||
const fixInfo = errorInfo.fixInfo;
|
const fixInfo = errorInfo.fixInfo;
|
||||||
|
const cleanFixInfo = {};
|
||||||
if (fixInfo) {
|
if (fixInfo) {
|
||||||
if (!helpers.isObject(fixInfo)) {
|
if (!helpers.isObject(fixInfo)) {
|
||||||
throwError("fixInfo");
|
throwError("fixInfo");
|
||||||
}
|
}
|
||||||
if ((fixInfo.lineNumber !== undefined) &&
|
if (fixInfo.lineNumber !== undefined) {
|
||||||
(!helpers.isNumber(fixInfo.lineNumber) ||
|
if ((!helpers.isNumber(fixInfo.lineNumber) ||
|
||||||
(fixInfo.lineNumber < 1) ||
|
(fixInfo.lineNumber < 1) ||
|
||||||
(fixInfo.lineNumber > lines.length))) {
|
(fixInfo.lineNumber > lines.length))) {
|
||||||
throwError("fixInfo.lineNumber");
|
throwError("fixInfo.lineNumber");
|
||||||
|
}
|
||||||
|
cleanFixInfo.lineNumber =
|
||||||
|
fixInfo.lineNumber + frontMatterLines.length;
|
||||||
}
|
}
|
||||||
const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber;
|
const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber;
|
||||||
if ((fixInfo.editColumn !== undefined) &&
|
if (fixInfo.editColumn !== undefined) {
|
||||||
(!helpers.isNumber(fixInfo.editColumn) ||
|
if ((!helpers.isNumber(fixInfo.editColumn) ||
|
||||||
(fixInfo.editColumn < 1) ||
|
(fixInfo.editColumn < 1) ||
|
||||||
(fixInfo.editColumn >
|
(fixInfo.editColumn >
|
||||||
lines[effectiveLineNumber - 1].length + 1))) {
|
lines[effectiveLineNumber - 1].length + 1))) {
|
||||||
throwError("fixInfo.editColumn");
|
throwError("fixInfo.editColumn");
|
||||||
|
}
|
||||||
|
cleanFixInfo.editColumn = fixInfo.editColumn;
|
||||||
}
|
}
|
||||||
if ((fixInfo.deleteCount !== undefined) &&
|
if (fixInfo.deleteCount !== undefined) {
|
||||||
(!helpers.isNumber(fixInfo.deleteCount) ||
|
if ((!helpers.isNumber(fixInfo.deleteCount) ||
|
||||||
(fixInfo.deleteCount < -1) ||
|
(fixInfo.deleteCount < -1) ||
|
||||||
(fixInfo.deleteCount >
|
(fixInfo.deleteCount >
|
||||||
lines[effectiveLineNumber - 1].length))) {
|
lines[effectiveLineNumber - 1].length))) {
|
||||||
throwError("fixInfo.deleteCount");
|
throwError("fixInfo.deleteCount");
|
||||||
|
}
|
||||||
|
cleanFixInfo.deleteCount = fixInfo.deleteCount;
|
||||||
}
|
}
|
||||||
if ((fixInfo.insertText !== undefined) &&
|
if (fixInfo.insertText !== undefined) {
|
||||||
!helpers.isString(fixInfo.insertText)) {
|
if (!helpers.isString(fixInfo.insertText)) {
|
||||||
throwError("fixInfo.insertText");
|
throwError("fixInfo.insertText");
|
||||||
|
}
|
||||||
|
cleanFixInfo.insertText = fixInfo.insertText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errors.push({
|
errors.push({
|
||||||
|
|
@ -427,7 +437,7 @@ function lintContent(
|
||||||
"detail": errorInfo.detail || null,
|
"detail": errorInfo.detail || null,
|
||||||
"context": errorInfo.context || null,
|
"context": errorInfo.context || null,
|
||||||
"range": errorInfo.range || null,
|
"range": errorInfo.range || null,
|
||||||
"fixInfo": errorInfo.fixInfo || null
|
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Call (possibly external) rule function
|
// Call (possibly external) rule function
|
||||||
|
|
|
||||||
11
test/detailed-results-fixing-with-front-matter.md
Normal file
11
test/detailed-results-fixing-with-front-matter.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
front: matter
|
||||||
|
ignore: this
|
||||||
|
---
|
||||||
|
# Fixing with Front Matter
|
||||||
|
Text text text
|
||||||
|
|
||||||
|
Text [ link ](url) text
|
||||||
|
## Nested Heading
|
||||||
|
|
||||||
|
Text
|
||||||
13
test/detailed-results-fixing-with-front-matter.md.fixed
Normal file
13
test/detailed-results-fixing-with-front-matter.md.fixed
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
front: matter
|
||||||
|
ignore: this
|
||||||
|
---
|
||||||
|
# Fixing with Front Matter
|
||||||
|
|
||||||
|
Text text text
|
||||||
|
|
||||||
|
Text [link](url) text
|
||||||
|
|
||||||
|
## Nested Heading
|
||||||
|
|
||||||
|
Text
|
||||||
47
test/detailed-results-fixing-with-front-matter.results.json
Normal file
47
test/detailed-results-fixing-with-front-matter.results.json
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"lineNumber": 6,
|
||||||
|
"ruleNames": [ "MD009", "no-trailing-spaces" ],
|
||||||
|
"ruleDescription": "Trailing spaces",
|
||||||
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md009",
|
||||||
|
"errorDetail": "Expected: 0 or 2; Actual: 3",
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": [ 15, 3 ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 5,
|
||||||
|
"ruleNames": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
|
||||||
|
"ruleDescription": "Headings should be surrounded by blank lines",
|
||||||
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md022",
|
||||||
|
"errorDetail": "Expected: 1; Actual: 0; Below",
|
||||||
|
"errorContext": "# Fixing with Front Matter",
|
||||||
|
"errorRange": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 9,
|
||||||
|
"ruleNames": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
|
||||||
|
"ruleDescription": "Headings should be surrounded by blank lines",
|
||||||
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md022",
|
||||||
|
"errorDetail": "Expected: 1; Actual: 0; Above",
|
||||||
|
"errorContext": "## Nested Heading",
|
||||||
|
"errorRange": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 8,
|
||||||
|
"ruleNames": [ "MD039", "no-space-in-links" ],
|
||||||
|
"ruleDescription": "Spaces inside link text",
|
||||||
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039",
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": "[ link ]",
|
||||||
|
"errorRange": [ 6, 8 ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lineNumber": 11,
|
||||||
|
"ruleNames": [ "MD047", "single-trailing-newline" ],
|
||||||
|
"ruleDescription": "Files should end with a single newline character",
|
||||||
|
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md047",
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": [ 4, 1 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -751,6 +751,41 @@ module.exports.manyPerLineResultVersion3 =
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.frontMatterResultVersion3 =
|
||||||
|
function frontMatterResultVersion3(test) {
|
||||||
|
test.expect(2);
|
||||||
|
const options = {
|
||||||
|
"strings": {
|
||||||
|
"input": "---\n---\n# Heading\nText\n"
|
||||||
|
},
|
||||||
|
"resultVersion": 3
|
||||||
|
};
|
||||||
|
markdownlint(options, function callback(err, actualResult) {
|
||||||
|
test.ifError(err);
|
||||||
|
const expectedResult = {
|
||||||
|
"input": [
|
||||||
|
{
|
||||||
|
"lineNumber": 3,
|
||||||
|
"ruleNames":
|
||||||
|
[ "MD022", "blanks-around-headings", "blanks-around-headers" ],
|
||||||
|
"ruleDescription": "Headings should be surrounded by blank lines",
|
||||||
|
"ruleInformation":
|
||||||
|
`${homepage}/blob/v${version}/doc/Rules.md#md022`,
|
||||||
|
"errorDetail": "Expected: 1; Actual: 0; Below",
|
||||||
|
"errorContext": "# Heading",
|
||||||
|
"errorRange": null,
|
||||||
|
"fixInfo": {
|
||||||
|
"lineNumber": 4,
|
||||||
|
"insertText": "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
|
module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
const options = {
|
const options = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue