Skip to content

Commit

Permalink
Add rule name and file/string identifier to Error message thrown by o…
Browse files Browse the repository at this point in the history
…nError validation for rules.
  • Loading branch information
DavidAnson committed Oct 8, 2023
1 parent 74f4163 commit d2faf40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,8 @@ function lintContent(ruleList, aliasToRuleNames, name, content, md, config, conf
});
// eslint-disable-next-line jsdoc/require-jsdoc
function throwError(property) {
throw new Error("Property '" + property + "' of onError parameter is incorrect.");
throw new Error( // eslint-disable-next-line max-len
"Value of '".concat(property, "' passed to onError by '").concat(ruleName, "' is incorrect for '").concat(name, "'."));
}
// eslint-disable-next-line jsdoc/require-jsdoc
function onError(errorInfo) {
Expand Down
3 changes: 2 additions & 1 deletion lib/markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ function lintContent(
// eslint-disable-next-line jsdoc/require-jsdoc
function throwError(property) {
throw new Error(
"Property '" + property + "' of onError parameter is incorrect.");
// eslint-disable-next-line max-len
`Value of '${property}' passed to onError by '${ruleName}' is incorrect for '${name}'.`);
}
// eslint-disable-next-line jsdoc/require-jsdoc
function onError(errorInfo) {
Expand Down
18 changes: 12 additions & 6 deletions test/markdownlint-test-custom-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ test("customRulesOnErrorNull", (t) => new Promise((resolve) => {
t.is(
// @ts-ignore
err.message,
"Property 'lineNumber' of onError parameter is incorrect.",
// eslint-disable-next-line max-len
"Value of 'lineNumber' passed to onError by 'NAME' is incorrect for 'string'.",
"Did not get correct exception for null object."
);
t.true(!result, "Got result for function thrown.");
Expand Down Expand Up @@ -686,7 +687,8 @@ test("customRulesOnErrorNullSync", (t) => {
markdownlint.sync(options);
},
{
"message": "Property 'lineNumber' of onError parameter is incorrect."
// eslint-disable-next-line max-len
"message": "Value of 'lineNumber' passed to onError by 'NAME' is incorrect for 'string'."
},
"Did not get correct exception for null object."
);
Expand Down Expand Up @@ -775,7 +777,8 @@ test("customRulesOnErrorBad", (t) => {
},
{
"message":
`Property '${propertyNames}' of onError parameter is incorrect.`
// eslint-disable-next-line max-len
`Value of '${propertyNames}' passed to onError by 'NAME' is incorrect for 'string'.`
},
"Did not get correct exception for bad object."
);
Expand Down Expand Up @@ -845,7 +848,8 @@ test("customRulesOnErrorInvalid", (t) => {
},
{
"message":
`Property '${propertyNames}' of onError parameter is incorrect.`
// eslint-disable-next-line max-len
`Value of '${propertyNames}' passed to onError by 'NAME' is incorrect for 'string'.`
},
"Did not get correct exception for invalid object."
);
Expand Down Expand Up @@ -1052,7 +1056,8 @@ test("customRulesOnErrorInvalidHandled", (t) => new Promise((resolve) => {
"ruleDescription": "description",
"ruleInformation": null,
"errorDetail": "This rule threw an exception: " +
"Property 'lineNumber' of onError parameter is incorrect.",
// eslint-disable-next-line max-len
"Value of 'lineNumber' passed to onError by 'NAME' is incorrect for 'string'.",
"errorContext": null,
"errorRange": null,
"fixInfo": null
Expand Down Expand Up @@ -1093,7 +1098,8 @@ test("customRulesOnErrorInvalidHandledSync", (t) => {
"ruleDescription": "description",
"ruleInformation": null,
"errorDetail": "This rule threw an exception: " +
"Property 'lineNumber' of onError parameter is incorrect.",
// eslint-disable-next-line max-len
"Value of 'lineNumber' passed to onError by 'NAME' is incorrect for 'string'.",
"errorContext": null,
"errorRange": null,
"fixInfo": null
Expand Down

0 comments on commit d2faf40

Please sign in to comment.