mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Snapshot custom rule definitions to prevent them from changing dynamically.
This commit is contained in:
parent
c699b8e22b
commit
14a7529ce7
3 changed files with 54 additions and 2 deletions
|
@ -2628,8 +2628,11 @@ function lintInput(options, synchronous, callback) {
|
|||
// Normalize inputs
|
||||
options = options || {};
|
||||
callback = callback || function noop() {};
|
||||
var customRuleList = [options.customRules || []].flat().map(function (rule) {
|
||||
return _objectSpread({}, rule);
|
||||
});
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
var ruleList = rules.concat(options.customRules || []);
|
||||
var ruleList = rules.concat(customRuleList);
|
||||
var ruleErr = validateRuleList(ruleList, synchronous);
|
||||
if (ruleErr) {
|
||||
callback(ruleErr);
|
||||
|
|
|
@ -869,8 +869,12 @@ function lintInput(options, synchronous, callback) {
|
|||
// Normalize inputs
|
||||
options = options || {};
|
||||
callback = callback || function noop() {};
|
||||
const customRuleList =
|
||||
[ options.customRules || [] ]
|
||||
.flat()
|
||||
.map((rule) => ({ ...rule }));
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
const ruleList = rules.concat(options.customRules || []);
|
||||
const ruleList = rules.concat(customRuleList);
|
||||
const ruleErr = validateRuleList(ruleList, synchronous);
|
||||
if (ruleErr) {
|
||||
callback(ruleErr);
|
||||
|
|
|
@ -479,6 +479,51 @@ test("customRulesUsedTagName", (t) => new Promise((resolve) => {
|
|||
});
|
||||
}));
|
||||
|
||||
test("customRulesDefinitionStatic", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
const options = {
|
||||
"customRules": [
|
||||
{
|
||||
"names": [ "name" ],
|
||||
"description": "description",
|
||||
"information": new URL("https://example.com/information"),
|
||||
"tags": [ "tag" ],
|
||||
"function": (params, onError) => {
|
||||
const definition = options.customRules[0];
|
||||
definition.names = [ "changed" ];
|
||||
definition.description = "changed";
|
||||
definition.information = new URL("https://example.com/changed");
|
||||
onError({
|
||||
"lineNumber": 1
|
||||
});
|
||||
}
|
||||
}
|
||||
],
|
||||
"strings": {
|
||||
"string": "# Heading\n"
|
||||
}
|
||||
};
|
||||
markdownlint(options, (err, actualResult) => {
|
||||
t.falsy(err);
|
||||
const expectedResult = {
|
||||
"string": [
|
||||
{
|
||||
"lineNumber": 1,
|
||||
"ruleNames": [ "name" ],
|
||||
"ruleDescription": "description",
|
||||
"ruleInformation": "https://example.com/information",
|
||||
"errorDetail": null,
|
||||
"errorContext": null,
|
||||
"errorRange": null,
|
||||
"fixInfo": null
|
||||
}
|
||||
]
|
||||
};
|
||||
t.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
|
||||
test("customRulesThrowForFile", (t) => new Promise((resolve) => {
|
||||
t.plan(4);
|
||||
const exceptionMessage = "Test exception message";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue