Update MD053/link-image-reference-definitions to add ignored_definitions parameter (default to ["//"]) (fixes #545).

This commit is contained in:
David Anson 2022-08-02 20:36:47 -07:00
parent 2c3e8c938b
commit a6489acd6b
14 changed files with 234 additions and 31 deletions

View file

@ -38,7 +38,7 @@ module.exports = {
const unescaped = unescapeMarkdown(prefix + "<", "_");
if (!unescaped.endsWith("_")) {
addError(onError, lineIndex + 1, "Element: " + element,
null, [ match.index + 1, tag.length ]);
undefined, [ match.index + 1, tag.length ]);
}
}
}

View file

@ -11,7 +11,8 @@ module.exports = {
"description": "Link and image reference definitions should be needed",
"tags": [ "images", "links" ],
"function": function MD053(params, onError) {
const { lines } = params;
const ignored = new Set(params.config.ignored_definitions || [ "//" ]);
const lines = params.lines;
const { references, shortcuts, definitions, duplicateDefinitions } =
referenceLinkImageData();
const singleLineDefinition = (line) => (
@ -23,7 +24,11 @@ module.exports = {
// Look for unused link references (unreferenced by any link/image)
for (const definition of definitions.entries()) {
const [ label, lineIndex ] = definition;
if (!references.has(label) && !shortcuts.has(label)) {
if (
!ignored.has(label) &&
!references.has(label) &&
!shortcuts.has(label)
) {
const line = lines[lineIndex];
addError(
onError,
@ -38,15 +43,17 @@ module.exports = {
// Look for duplicate link references (defined more than once)
for (const duplicateDefinition of duplicateDefinitions) {
const [ label, lineIndex ] = duplicateDefinition;
const line = lines[lineIndex];
addError(
onError,
lineIndex + 1,
`Duplicate link or image reference definition: "${label}"`,
ellipsify(line),
[ 1, line.length ],
singleLineDefinition(line) ? deleteFixInfo : 0
);
if (!ignored.has(label)) {
const line = lines[lineIndex];
addError(
onError,
lineIndex + 1,
`Duplicate link or image reference definition: "${label}"`,
ellipsify(line),
[ 1, line.length ],
singleLineDefinition(line) ? deleteFixInfo : 0
);
}
}
}
};