mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Stop sharing params object across rules because doing so is unstable for asynchronous rules (fixes #510).
This commit is contained in:
parent
4affefc68d
commit
62f5c85238
3 changed files with 87 additions and 20 deletions
|
|
@ -1498,22 +1498,22 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul
|
||||||
var aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
var aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
||||||
var _a = getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, aliasToRuleNames), effectiveConfig = _a.effectiveConfig, enabledRulesPerLineNumber = _a.enabledRulesPerLineNumber;
|
var _a = getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, aliasToRuleNames), effectiveConfig = _a.effectiveConfig, enabledRulesPerLineNumber = _a.enabledRulesPerLineNumber;
|
||||||
// Create parameters for rules
|
// Create parameters for rules
|
||||||
var params = {
|
var paramsBase = helpers.deepFreeze({
|
||||||
"name": helpers.deepFreeze(name),
|
name: name,
|
||||||
"tokens": helpers.deepFreeze(tokens),
|
tokens: tokens,
|
||||||
"lines": helpers.deepFreeze(lines),
|
lines: lines,
|
||||||
"frontMatterLines": helpers.deepFreeze(frontMatterLines)
|
frontMatterLines: frontMatterLines
|
||||||
};
|
});
|
||||||
cache.lineMetadata(helpers.getLineMetadata(params));
|
cache.lineMetadata(helpers.getLineMetadata(paramsBase));
|
||||||
cache.flattenedLists(helpers.flattenLists(params.tokens));
|
cache.flattenedLists(helpers.flattenLists(paramsBase.tokens));
|
||||||
cache.codeBlockAndSpanRanges(helpers.codeBlockAndSpanRanges(params, cache.lineMetadata()));
|
cache.codeBlockAndSpanRanges(helpers.codeBlockAndSpanRanges(paramsBase, cache.lineMetadata()));
|
||||||
// Function to run for each rule
|
// Function to run for each rule
|
||||||
var results = [];
|
var results = [];
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function forRule(rule) {
|
function forRule(rule) {
|
||||||
// Configure rule
|
// Configure rule
|
||||||
var ruleName = rule.names[0].toUpperCase();
|
var ruleName = rule.names[0].toUpperCase();
|
||||||
params.config = effectiveConfig[ruleName];
|
var params = __assign(__assign({}, paramsBase), { "config": effectiveConfig[ruleName] });
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function throwError(property) {
|
function throwError(property) {
|
||||||
throw new Error("Property '" + property + "' of onError parameter is incorrect.");
|
throw new Error("Property '" + property + "' of onError parameter is incorrect.");
|
||||||
|
|
|
||||||
|
|
@ -489,16 +489,16 @@ function lintContent(
|
||||||
aliasToRuleNames
|
aliasToRuleNames
|
||||||
);
|
);
|
||||||
// Create parameters for rules
|
// Create parameters for rules
|
||||||
const params = {
|
const paramsBase = helpers.deepFreeze({
|
||||||
"name": helpers.deepFreeze(name),
|
name,
|
||||||
"tokens": helpers.deepFreeze(tokens),
|
tokens,
|
||||||
"lines": helpers.deepFreeze(lines),
|
lines,
|
||||||
"frontMatterLines": helpers.deepFreeze(frontMatterLines)
|
frontMatterLines
|
||||||
};
|
});
|
||||||
cache.lineMetadata(helpers.getLineMetadata(params));
|
cache.lineMetadata(helpers.getLineMetadata(paramsBase));
|
||||||
cache.flattenedLists(helpers.flattenLists(params.tokens));
|
cache.flattenedLists(helpers.flattenLists(paramsBase.tokens));
|
||||||
cache.codeBlockAndSpanRanges(
|
cache.codeBlockAndSpanRanges(
|
||||||
helpers.codeBlockAndSpanRanges(params, cache.lineMetadata())
|
helpers.codeBlockAndSpanRanges(paramsBase, cache.lineMetadata())
|
||||||
);
|
);
|
||||||
// Function to run for each rule
|
// Function to run for each rule
|
||||||
let results = [];
|
let results = [];
|
||||||
|
|
@ -506,7 +506,10 @@ function lintContent(
|
||||||
function forRule(rule) {
|
function forRule(rule) {
|
||||||
// Configure rule
|
// Configure rule
|
||||||
const ruleName = rule.names[0].toUpperCase();
|
const ruleName = rule.names[0].toUpperCase();
|
||||||
params.config = effectiveConfig[ruleName];
|
const params = {
|
||||||
|
...paramsBase,
|
||||||
|
"config": effectiveConfig[ruleName]
|
||||||
|
};
|
||||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function throwError(property) {
|
function throwError(property) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
||||||
|
|
@ -1195,6 +1195,70 @@ test("customRulesAsyncThrowsInSyncContext", (t) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("customRulesParamsAreStable", (t) => {
|
||||||
|
t.plan(4);
|
||||||
|
const config1 = { "value1": 10 };
|
||||||
|
const config2 = { "value2": 20 };
|
||||||
|
const options = {
|
||||||
|
"config": {
|
||||||
|
"MD010": true,
|
||||||
|
"name1": config1,
|
||||||
|
"MD013": { "line_length": 200 },
|
||||||
|
"name2": config2,
|
||||||
|
"MD033": false
|
||||||
|
},
|
||||||
|
"customRules": [
|
||||||
|
{
|
||||||
|
"names": [ "name1" ],
|
||||||
|
"description": "description1",
|
||||||
|
"tags": [ "tag" ],
|
||||||
|
"asynchronous": true,
|
||||||
|
"function":
|
||||||
|
(params) => {
|
||||||
|
t.deepEqual(
|
||||||
|
params.config,
|
||||||
|
config1,
|
||||||
|
`Unexpected config in sync path: ${params.config}.`
|
||||||
|
);
|
||||||
|
return Promise.resolve().then(() => {
|
||||||
|
t.deepEqual(
|
||||||
|
params.config,
|
||||||
|
config1,
|
||||||
|
`Unexpected config in async path: ${params.config}.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"names": [ "name2" ],
|
||||||
|
"description": "description2",
|
||||||
|
"tags": [ "tag" ],
|
||||||
|
"asynchronous": true,
|
||||||
|
"function":
|
||||||
|
(params) => {
|
||||||
|
const { config } = params;
|
||||||
|
t.deepEqual(
|
||||||
|
config,
|
||||||
|
config2,
|
||||||
|
`Unexpected config in sync path: ${config}.`
|
||||||
|
);
|
||||||
|
return Promise.resolve().then(() => {
|
||||||
|
t.deepEqual(
|
||||||
|
config,
|
||||||
|
config2,
|
||||||
|
`Unexpected config in async path: ${config}.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"strings": {
|
||||||
|
"string": "# Heading"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return markdownlint.promises.markdownlint(options).then(() => null);
|
||||||
|
});
|
||||||
|
|
||||||
test("customRulesAsyncReadFiles", (t) => {
|
test("customRulesAsyncReadFiles", (t) => {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
const options = {
|
const options = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue