mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Copy range property of rule's onError object at time of call; add test to verify.
This commit is contained in:
parent
d15324478c
commit
5f6e17915a
2 changed files with 63 additions and 2 deletions
|
|
@ -448,7 +448,7 @@ function lintContent(
|
||||||
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
|
||||||
"detail": errorInfo.detail || null,
|
"detail": errorInfo.detail || null,
|
||||||
"context": errorInfo.context || null,
|
"context": errorInfo.context || null,
|
||||||
"range": errorInfo.range || null,
|
"range": errorInfo.range ? [ ...errorInfo.range ] : null,
|
||||||
"fixInfo": fixInfo ? cleanFixInfo : null
|
"fixInfo": fixInfo ? cleanFixInfo : null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3609,7 +3609,7 @@ tape("customRulesOnErrorLazy", (test) => {
|
||||||
"names": [ "name" ],
|
"names": [ "name" ],
|
||||||
"description": "description",
|
"description": "description",
|
||||||
"tags": [ "tag" ],
|
"tags": [ "tag" ],
|
||||||
"function": function onErrorNull(params, onError) {
|
"function": function onErrorLazy(params, onError) {
|
||||||
onError({
|
onError({
|
||||||
"lineNumber": 1,
|
"lineNumber": 1,
|
||||||
"detail": "",
|
"detail": "",
|
||||||
|
|
@ -3643,6 +3643,67 @@ tape("customRulesOnErrorLazy", (test) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tape("customRulesOnErrorModified", (test) => {
|
||||||
|
test.plan(2);
|
||||||
|
const errorObject = {
|
||||||
|
"lineNumber": 1,
|
||||||
|
"detail": "detail",
|
||||||
|
"context": "context",
|
||||||
|
"range": [ 1, 2 ],
|
||||||
|
"fixInfo": {
|
||||||
|
"editColumn": 1,
|
||||||
|
"deleteCount": 2,
|
||||||
|
"insertText": "text"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const options = {
|
||||||
|
"customRules": [
|
||||||
|
{
|
||||||
|
"names": [ "name" ],
|
||||||
|
"description": "description",
|
||||||
|
"tags": [ "tag" ],
|
||||||
|
"function": function onErrorModified(params, onError) {
|
||||||
|
onError(errorObject);
|
||||||
|
errorObject.lineNumber = 2;
|
||||||
|
errorObject.detail = "changed";
|
||||||
|
errorObject.context = "changed";
|
||||||
|
errorObject.range[1] = 3;
|
||||||
|
errorObject.fixInfo.editColumn = 2;
|
||||||
|
errorObject.fixInfo.deleteCount = 3;
|
||||||
|
errorObject.fixInfo.insertText = "changed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"strings": {
|
||||||
|
"string": "# Heading\n"
|
||||||
|
},
|
||||||
|
"resultVersion": 3
|
||||||
|
};
|
||||||
|
markdownlint(options, function callback(err, actualResult) {
|
||||||
|
test.ifError(err);
|
||||||
|
const expectedResult = {
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"lineNumber": 1,
|
||||||
|
"ruleNames": [ "name" ],
|
||||||
|
"ruleDescription": "description",
|
||||||
|
"ruleInformation": null,
|
||||||
|
"errorDetail": "detail",
|
||||||
|
"errorContext": "context",
|
||||||
|
"errorRange": [ 1, 2 ],
|
||||||
|
"fixInfo": {
|
||||||
|
"editColumn": 1,
|
||||||
|
"deleteCount": 2,
|
||||||
|
"insertText": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||||
|
test.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
tape("customRulesThrowForFileHandled", (test) => {
|
tape("customRulesThrowForFileHandled", (test) => {
|
||||||
test.plan(2);
|
test.plan(2);
|
||||||
const exceptionMessage = "Test exception message";
|
const exceptionMessage = "Test exception message";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue