diff --git a/doc-build/md052.md b/doc-build/md052.md index bf368f4a..064b8dbd 100644 --- a/doc-build/md052.md +++ b/doc-build/md052.md @@ -28,3 +28,14 @@ so "shortcut" syntax is ignored by default. To include "shortcut" syntax, set the `include_shortcut` parameter to `true`. Note that doing so produces warnings for *all* text in the document that *could* be a shortcut. If bracketed text is intentional, brackets can be escaped with the `\` character: `\[example\]`. + +If there are link labels that are deliberately unreferenced, they can be ignored +by setting the `ignored_labels` parameter to the list of strings to ignore. The +default value of this parameter ignores the checkbox syntax used by +[GitHub Flavored Markdown task list items][gfm-tasklist]: + +```markdown +- [x] Checked task list item +``` + +[gfm-tasklist]: https://github.github.com/gfm/#task-list-items-extension- diff --git a/doc-build/md053.md b/doc-build/md053.md index 9869bd1f..1da909c7 100644 --- a/doc-build/md053.md +++ b/doc-build/md053.md @@ -17,9 +17,9 @@ reference has the corresponding label. The "full", "collapsed", and "shortcut" formats are all supported. If there are reference definitions that are deliberately unreferenced, they can -be ignored by setting the `ignored_definitions` parameter. The default value of -this parameter ignores the following convention for adding non-HTML comments to -Markdown: +be ignored by setting the `ignored_definitions` parameter to the list of strings +to ignore. The default value of this parameter ignores the following convention +for adding non-HTML comments to Markdown: ```markdown [//]: # (This behaves like a comment) diff --git a/doc/Rules.md b/doc/Rules.md index 6287efe8..6ebb79bb 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -2278,6 +2278,7 @@ Aliases: `reference-links-images` Parameters: +- `ignored_labels`: Ignored link labels (`string[]`, default `["x"]`) - `shortcut_syntax`: Include shortcut syntax (`boolean`, default `false`) Links and images in Markdown can provide the link destination or image source @@ -2311,6 +2312,17 @@ the `include_shortcut` parameter to `true`. Note that doing so produces warnings for *all* text in the document that *could* be a shortcut. If bracketed text is intentional, brackets can be escaped with the `\` character: `\[example\]`. +If there are link labels that are deliberately unreferenced, they can be ignored +by setting the `ignored_labels` parameter to the list of strings to ignore. The +default value of this parameter ignores the checkbox syntax used by +[GitHub Flavored Markdown task list items][gfm-tasklist]: + +```markdown +- [x] Checked task list item +``` + +[gfm-tasklist]: https://github.github.com/gfm/#task-list-items-extension- + ## `MD053` - Link and image reference definitions should be needed @@ -2344,9 +2356,9 @@ reference has the corresponding label. The "full", "collapsed", and "shortcut" formats are all supported. If there are reference definitions that are deliberately unreferenced, they can -be ignored by setting the `ignored_definitions` parameter. The default value of -this parameter ignores the following convention for adding non-HTML comments to -Markdown: +be ignored by setting the `ignored_definitions` parameter to the list of strings +to ignore. The default value of this parameter ignores the following convention +for adding non-HTML comments to Markdown: ```markdown [//]: # (This behaves like a comment) diff --git a/doc/md052.md b/doc/md052.md index 994d98ee..e8544f70 100644 --- a/doc/md052.md +++ b/doc/md052.md @@ -6,6 +6,7 @@ Aliases: `reference-links-images` Parameters: +- `ignored_labels`: Ignored link labels (`string[]`, default `["x"]`) - `shortcut_syntax`: Include shortcut syntax (`boolean`, default `false`) Links and images in Markdown can provide the link destination or image source @@ -38,3 +39,14 @@ so "shortcut" syntax is ignored by default. To include "shortcut" syntax, set the `include_shortcut` parameter to `true`. Note that doing so produces warnings for *all* text in the document that *could* be a shortcut. If bracketed text is intentional, brackets can be escaped with the `\` character: `\[example\]`. + +If there are link labels that are deliberately unreferenced, they can be ignored +by setting the `ignored_labels` parameter to the list of strings to ignore. The +default value of this parameter ignores the checkbox syntax used by +[GitHub Flavored Markdown task list items][gfm-tasklist]: + +```markdown +- [x] Checked task list item +``` + +[gfm-tasklist]: https://github.github.com/gfm/#task-list-items-extension- diff --git a/doc/md053.md b/doc/md053.md index 7caf0290..96b1104d 100644 --- a/doc/md053.md +++ b/doc/md053.md @@ -29,9 +29,9 @@ reference has the corresponding label. The "full", "collapsed", and "shortcut" formats are all supported. If there are reference definitions that are deliberately unreferenced, they can -be ignored by setting the `ignored_definitions` parameter. The default value of -this parameter ignores the following convention for adding non-HTML comments to -Markdown: +be ignored by setting the `ignored_definitions` parameter to the list of strings +to ignore. The default value of this parameter ignores the following convention +for adding non-HTML comments to Markdown: ```markdown [//]: # (This behaves like a comment) diff --git a/lib/configuration-strict.d.ts b/lib/configuration-strict.d.ts index 045d6d4e..ca4290d2 100644 --- a/lib/configuration-strict.d.ts +++ b/lib/configuration-strict.d.ts @@ -996,6 +996,10 @@ export interface ConfigurationStrict { MD052?: | boolean | { + /** + * Ignored link labels + */ + ignored_labels?: string[]; /** * Include shortcut syntax */ @@ -1007,6 +1011,10 @@ export interface ConfigurationStrict { "reference-links-images"?: | boolean | { + /** + * Ignored link labels + */ + ignored_labels?: string[]; /** * Include shortcut syntax */ diff --git a/lib/md052.mjs b/lib/md052.mjs index 975c45c6..a87215e3 100644 --- a/lib/md052.mjs +++ b/lib/md052.mjs @@ -13,6 +13,7 @@ export default { "function": function MD052(params, onError) { const { config, lines } = params; const shortcutSyntax = config.shortcut_syntax || false; + const ignoredLabels = new Set(config.ignored_labels || [ "x" ]); const { definitions, references, shortcuts } = getReferenceLinkImageData(); const entries = shortcutSyntax ? [ ...references.entries(), ...shortcuts.entries() ] : @@ -20,7 +21,7 @@ export default { // Look for links/images that use an undefined link reference for (const reference of entries) { const [ label, datas ] = reference; - if (!definitions.has(label)) { + if (!definitions.has(label) && !ignoredLabels.has(label)) { for (const data of datas) { const [ lineIndex, index, length ] = data; // Context will be incomplete if reporting for a multi-line link diff --git a/schema/.markdownlint.jsonc b/schema/.markdownlint.jsonc index b1496dca..78382bd2 100644 --- a/schema/.markdownlint.jsonc +++ b/schema/.markdownlint.jsonc @@ -275,6 +275,10 @@ // MD052/reference-links-images : Reference links and images should use a label that is defined : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md052.md "MD052": { + // Ignored link labels + "ignored_labels": [ + "x" + ], // Include shortcut syntax "shortcut_syntax": false }, diff --git a/schema/.markdownlint.yaml b/schema/.markdownlint.yaml index b905e45a..91248b60 100644 --- a/schema/.markdownlint.yaml +++ b/schema/.markdownlint.yaml @@ -247,6 +247,9 @@ MD051: # MD052/reference-links-images : Reference links and images should use a label that is defined : https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md052.md MD052: + # Ignored link labels + ignored_labels: + - "x" # Include shortcut syntax shortcut_syntax: false diff --git a/schema/build-config-schema.mjs b/schema/build-config-schema.mjs index 553fc9d3..90980553 100644 --- a/schema/build-config-schema.mjs +++ b/schema/build-config-schema.mjs @@ -493,6 +493,14 @@ for (const rule of rules) { break; case "MD052": scheme.properties = { + "ignored_labels": { + "description": "Ignored link labels", + "type": "array", + "items": { + "type": "string" + }, + "default": [ "x" ] + }, "shortcut_syntax": { "description": "Include shortcut syntax", "type": "boolean", diff --git a/schema/markdownlint-config-schema-strict.json b/schema/markdownlint-config-schema-strict.json index 34514781..0efd5824 100644 --- a/schema/markdownlint-config-schema-strict.json +++ b/schema/markdownlint-config-schema-strict.json @@ -1549,6 +1549,16 @@ ], "default": true, "properties": { + "ignored_labels": { + "description": "Ignored link labels", + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "x" + ] + }, "shortcut_syntax": { "description": "Include shortcut syntax", "type": "boolean", @@ -1565,6 +1575,16 @@ ], "default": true, "properties": { + "ignored_labels": { + "description": "Ignored link labels", + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "x" + ] + }, "shortcut_syntax": { "description": "Include shortcut syntax", "type": "boolean", diff --git a/schema/markdownlint-config-schema.json b/schema/markdownlint-config-schema.json index 2f5860d7..39bce20a 100644 --- a/schema/markdownlint-config-schema.json +++ b/schema/markdownlint-config-schema.json @@ -1549,6 +1549,16 @@ ], "default": true, "properties": { + "ignored_labels": { + "description": "Ignored link labels", + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "x" + ] + }, "shortcut_syntax": { "description": "Include shortcut syntax", "type": "boolean", @@ -1565,6 +1575,16 @@ ], "default": true, "properties": { + "ignored_labels": { + "description": "Ignored link labels", + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "x" + ] + }, "shortcut_syntax": { "description": "Include shortcut syntax", "type": "boolean", diff --git a/test/markdownlint-test.mjs b/test/markdownlint-test.mjs index b78671b3..19cc6a85 100644 --- a/test/markdownlint-test.mjs +++ b/test/markdownlint-test.mjs @@ -908,7 +908,7 @@ test("readme", async(t) => { }); test("validateJsonUsingConfigSchemaStrict", async(t) => { - t.plan(199); + t.plan(201); // @ts-ignore const ajv = new Ajv(ajvOptions); const validateSchemaStrict = ajv.compile(configSchemaStrict); diff --git a/test/reference-links-and-images-ignored-labels-empty.md b/test/reference-links-and-images-ignored-labels-empty.md new file mode 100644 index 00000000..7339e58d --- /dev/null +++ b/test/reference-links-and-images-ignored-labels-empty.md @@ -0,0 +1,19 @@ +# Reference Links and Images (Ignored Labels Empty) + +[full][full] {MD052} + +[collapsed][] {MD052} + +[shortcut] {MD052} + +[invalid][invalid] {MD052} + +- [ ] Unchecked task list item +- [x] Checked task list item {MD052} + + diff --git a/test/reference-links-and-images-ignored-labels.md b/test/reference-links-and-images-ignored-labels.md new file mode 100644 index 00000000..3b055e83 --- /dev/null +++ b/test/reference-links-and-images-ignored-labels.md @@ -0,0 +1,23 @@ +# Reference Links and Images (Ignored Labels) + +[full][full] + +[collapsed][] + +[shortcut] + +[invalid][invalid] {MD052} + +- [ ] Unchecked task list item +- [x] Checked task list item {MD052} + + diff --git a/test/reference-links-and-images-shortcuts.md b/test/reference-links-and-images-shortcuts.md index e6765d64..16126f9f 100644 --- a/test/reference-links-and-images-shortcuts.md +++ b/test/reference-links-and-images-shortcuts.md @@ -84,6 +84,16 @@ Footnote[^1] Missing[^2] {MD052} +## GitHub Flavored Markdown Task List Items + +- [ ] Unchecked task list item +- [x] Checked task list item + +- [x] alpha + - [ ] beta + - [x] charlie +- [ ] delta + ## Valid Labels [label]: https://example.com/label diff --git a/test/reference-links-and-images.md b/test/reference-links-and-images.md index 95fdd4eb..474ad548 100644 --- a/test/reference-links-and-images.md +++ b/test/reference-links-and-images.md @@ -242,3 +242,8 @@ Text with a [^footnote] in it [^footnote]: Footnote with an [embedded-reference][] in it [embedded-reference]: https://example.com/embedded-reference + +## GitHub Flavored Markdown Task List Items + +- [ ] Unchecked task list item +- [x] Checked task list item diff --git a/test/snapshots/markdownlint-test-scenarios.mjs.md b/test/snapshots/markdownlint-test-scenarios.mjs.md index 765047fe..f28f91c4 100644 --- a/test/snapshots/markdownlint-test-scenarios.mjs.md +++ b/test/snapshots/markdownlint-test-scenarios.mjs.md @@ -47639,6 +47639,180 @@ Generated by [AVA](https://avajs.dev). `, } +## reference-links-and-images-ignored-labels-empty.md + +> Snapshot 1 + + { + errors: [ + { + errorContext: '[full][full]', + errorDetail: 'Missing link or image reference definition: "full"', + errorRange: [ + 1, + 12, + ], + fixInfo: null, + lineNumber: 3, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + { + errorContext: '[collapsed][]', + errorDetail: 'Missing link or image reference definition: "collapsed"', + errorRange: [ + 1, + 13, + ], + fixInfo: null, + lineNumber: 5, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + { + errorContext: '[shortcut]', + errorDetail: 'Missing link or image reference definition: "shortcut"', + errorRange: [ + 1, + 10, + ], + fixInfo: null, + lineNumber: 7, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + { + errorContext: '[invalid][invalid]', + errorDetail: 'Missing link or image reference definition: "invalid"', + errorRange: [ + 1, + 18, + ], + fixInfo: null, + lineNumber: 9, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + { + errorContext: '[x]', + errorDetail: 'Missing link or image reference definition: "x"', + errorRange: [ + 3, + 3, + ], + fixInfo: null, + lineNumber: 12, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + ], + fixed: `# Reference Links and Images (Ignored Labels Empty)␊ + ␊ + [full][full] {MD052}␊ + ␊ + [collapsed][] {MD052}␊ + ␊ + [shortcut] {MD052}␊ + ␊ + [invalid][invalid] {MD052}␊ + ␊ + - [ ] Unchecked task list item␊ + - [x] Checked task list item {MD052}␊ + ␊ + ␊ + `, + } + +## reference-links-and-images-ignored-labels.md + +> Snapshot 1 + + { + errors: [ + { + errorContext: '[invalid][invalid]', + errorDetail: 'Missing link or image reference definition: "invalid"', + errorRange: [ + 1, + 18, + ], + fixInfo: null, + lineNumber: 9, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + { + errorContext: '[x]', + errorDetail: 'Missing link or image reference definition: "x"', + errorRange: [ + 3, + 3, + ], + fixInfo: null, + lineNumber: 12, + ruleDescription: 'Reference links and images should use a label that is defined', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md052.md', + ruleNames: [ + 'MD052', + 'reference-links-images', + ], + }, + ], + fixed: `# Reference Links and Images (Ignored Labels)␊ + ␊ + [full][full]␊ + ␊ + [collapsed][]␊ + ␊ + [shortcut]␊ + ␊ + [invalid][invalid] {MD052}␊ + ␊ + - [ ] Unchecked task list item␊ + - [x] Checked task list item {MD052}␊ + ␊ + ␊ + `, + } + ## reference-links-and-images-shortcuts.md > Snapshot 1 @@ -47657,7 +47831,7 @@ Generated by [AVA](https://avajs.dev). editColumn: 7, insertText: '', }, - lineNumber: 106, + lineNumber: 116, ruleDescription: 'Bare URL used', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md', ruleNames: [ @@ -47848,6 +48022,16 @@ Generated by [AVA](https://avajs.dev). ␊ Missing[^2] {MD052}␊ ␊ + ## GitHub Flavored Markdown Task List Items␊ + ␊ + - [ ] Unchecked task list item␊ + - [x] Checked task list item␊ + ␊ + - [x] alpha␊ + - [ ] beta␊ + - [x] charlie␊ + - [ ] delta␊ + ␊ ## Valid Labels␊ ␊ [label]: https://example.com/label␊ @@ -48359,6 +48543,11 @@ Generated by [AVA](https://avajs.dev). [^footnote]: Footnote with an [embedded-reference][] in it␊ ␊ [embedded-reference]: https://example.com/embedded-reference␊ + ␊ + ## GitHub Flavored Markdown Task List Items␊ + ␊ + - [ ] Unchecked task list item␊ + - [x] Checked task list item␊ `, } diff --git a/test/snapshots/markdownlint-test-scenarios.mjs.snap b/test/snapshots/markdownlint-test-scenarios.mjs.snap index f585247b..f10223c2 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.mjs.snap and b/test/snapshots/markdownlint-test-scenarios.mjs.snap differ