mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Allow empty string for detail/context in onError callback from rules.
This commit is contained in:
parent
b3f0d76a67
commit
f80b61d8b7
3 changed files with 65 additions and 15 deletions
|
|
@ -326,16 +326,12 @@ function lintContent(
|
||||||
!shared.isNumber(errorInfo.lineNumber)) {
|
!shared.isNumber(errorInfo.lineNumber)) {
|
||||||
throwError("lineNumber");
|
throwError("lineNumber");
|
||||||
}
|
}
|
||||||
if ((errorInfo.detail !== null) &&
|
if (errorInfo.detail &&
|
||||||
(errorInfo.detail !== undefined) &&
|
!shared.isString(errorInfo.detail)) {
|
||||||
(!shared.isString(errorInfo.detail) ||
|
|
||||||
shared.isEmptyString(errorInfo.detail))) {
|
|
||||||
throwError("detail");
|
throwError("detail");
|
||||||
}
|
}
|
||||||
if ((errorInfo.context !== null) &&
|
if (errorInfo.context &&
|
||||||
(errorInfo.context !== undefined) &&
|
!shared.isString(errorInfo.context)) {
|
||||||
(!shared.isString(errorInfo.context) ||
|
|
||||||
shared.isEmptyString(errorInfo.context))) {
|
|
||||||
throwError("context");
|
throwError("context");
|
||||||
}
|
}
|
||||||
if (errorInfo.range &&
|
if (errorInfo.range &&
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,11 @@ $ code
|
||||||
|
|
||||||
text
|
text
|
||||||
|
|
||||||
{MD014:3} {MD014:9} {MD014:15} {MD014:22}
|
```sh
|
||||||
|
|
||||||
|
$ npm install --save multimatch
|
||||||
|
```
|
||||||
|
|
||||||
|
text
|
||||||
|
|
||||||
|
{MD014:3} {MD014:9} {MD014:15} {MD014:22} {MD014:29}
|
||||||
|
|
|
||||||
|
|
@ -1998,7 +1998,9 @@ function customRulesThrowForString(test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"strings": [ "String" ]
|
"strings": {
|
||||||
|
"string": "String"
|
||||||
|
}
|
||||||
}, function callback(err, result) {
|
}, function callback(err, result) {
|
||||||
test.ok(err, "Did not get an error for function thrown.");
|
test.ok(err, "Did not get an error for function thrown.");
|
||||||
test.ok(err instanceof Error, "Error not instance of Error.");
|
test.ok(err instanceof Error, "Error not instance of Error.");
|
||||||
|
|
@ -2022,7 +2024,9 @@ module.exports.customRulesOnErrorNull = function customRulesOnErrorNull(test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"strings": [ "String" ]
|
"strings": {
|
||||||
|
"string": "String"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
test.throws(function badErrorCall() {
|
test.throws(function badErrorCall() {
|
||||||
markdownlint.sync(options);
|
markdownlint.sync(options);
|
||||||
|
|
@ -2038,11 +2042,11 @@ module.exports.customRulesOnErrorNull = function customRulesOnErrorNull(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
|
module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
|
||||||
test.expect(52);
|
test.expect(44);
|
||||||
[
|
[
|
||||||
[ "lineNumber", [ null, "string" ] ],
|
[ "lineNumber", [ null, "string" ] ],
|
||||||
[ "detail", [ 10, "", [] ] ],
|
[ "detail", [ 10, [] ] ],
|
||||||
[ "context", [ 10, "", [] ] ],
|
[ "context", [ 10, [] ] ],
|
||||||
[ "range", [ 10, [], [ 10 ], [ 10, null ], [ 10, 11, 12 ] ] ]
|
[ "range", [ 10, [], [ 10 ], [ 10, null ], [ 10, 11, 12 ] ] ]
|
||||||
].forEach(function forProperty(property) {
|
].forEach(function forProperty(property) {
|
||||||
var propertyName = property[0];
|
var propertyName = property[0];
|
||||||
|
|
@ -2062,7 +2066,9 @@ module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"strings": [ "String" ]
|
"strings": {
|
||||||
|
"string": "String"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
test.throws(function badErrorCall() {
|
test.throws(function badErrorCall() {
|
||||||
markdownlint.sync(options);
|
markdownlint.sync(options);
|
||||||
|
|
@ -2079,6 +2085,47 @@ module.exports.customRulesOnErrorBad = function customRulesOnErrorBad(test) {
|
||||||
test.done();
|
test.done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.customRulesOnErrorLazy = function customRulesOnErrorLazy(test) {
|
||||||
|
test.expect(2);
|
||||||
|
var options = {
|
||||||
|
"customRules": [
|
||||||
|
{
|
||||||
|
"names": [ "name" ],
|
||||||
|
"description": "description",
|
||||||
|
"tags": [ "tag" ],
|
||||||
|
"function": function onErrorNull(params, onError) {
|
||||||
|
onError({
|
||||||
|
"lineNumber": 1,
|
||||||
|
"detail": "",
|
||||||
|
"context": "",
|
||||||
|
"range": [ 0, 0 ]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"strings": {
|
||||||
|
"string": "# Heading"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
markdownlint(options, function callback(err, actualResult) {
|
||||||
|
test.ifError(err);
|
||||||
|
var expectedResult = {
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"lineNumber": 1,
|
||||||
|
"ruleNames": [ "name" ],
|
||||||
|
"ruleDescription": "description",
|
||||||
|
"errorDetail": null,
|
||||||
|
"errorContext": null,
|
||||||
|
"errorRange": [ 0, 0 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.customRulesDoc = function customRulesDoc(test) {
|
module.exports.customRulesDoc = function customRulesDoc(test) {
|
||||||
test.expect(2);
|
test.expect(2);
|
||||||
markdownlint({
|
markdownlint({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue