mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +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
|
||||
|
|
|
|||
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) {
|
||||
test.expect(2);
|
||||
const options = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue