mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD053/link-image-reference-definitions to add ignored_definitions parameter (default to ["//"]) (fixes #545).
This commit is contained in:
parent
2c3e8c938b
commit
a6489acd6b
14 changed files with 234 additions and 31 deletions
|
@ -3658,7 +3658,7 @@ module.exports = {
|
|||
if (!linkDestinationRe.test(prefix)) {
|
||||
const unescaped = unescapeMarkdown(prefix + "<", "_");
|
||||
if (!unescaped.endsWith("_")) {
|
||||
addError(onError, lineIndex + 1, "Element: " + element, null, [match.index + 1, tag.length]);
|
||||
addError(onError, lineIndex + 1, "Element: " + element, undefined, [match.index + 1, tag.length]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4727,7 +4727,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) => (line.replace(linkReferenceDefinitionRe, "").trim().length > 0);
|
||||
const deleteFixInfo = {
|
||||
|
@ -4736,7 +4737,9 @@ 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, lineIndex + 1, `Unused link or image reference definition: "${label}"`, ellipsify(line), [1, line.length], singleLineDefinition(line) ? deleteFixInfo : 0);
|
||||
}
|
||||
|
@ -4744,8 +4747,10 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue