Reimplement MD039/no-space-in-links using micromark tokens.

This commit is contained in:
David Anson 2024-08-03 17:39:30 -07:00
parent 92a19b6f36
commit daa155d5a1
6 changed files with 265 additions and 124 deletions

View file

@ -1104,20 +1104,13 @@ test("someCustomRulesHaveValidUrl", (t) => {
});
test("markdownItPluginsSingle", (t) => new Promise((resolve) => {
t.plan(2);
t.plan(4);
markdownlint({
"strings": {
"string": "# Heading\n\nText [ link ](https://example.com)\n"
"string": "# Heading\n\nText\n"
},
"markdownItPlugins": [
[
pluginInline,
"trim_text_plugin",
"text",
function iterator(tokens, index) {
tokens[index].content = tokens[index].content.trim();
}
]
[ pluginInline, "check_text_plugin", "text", () => t.true(true) ]
]
}, function callback(err, actual) {
t.falsy(err);

View file

@ -51692,11 +51692,11 @@ Generated by [AVA](https://avajs.dev).
],
},
{
errorContext: '[ link with leading space]',
errorContext: '[ link with lea...space {MD039} ]',
errorDetail: null,
errorRange: null,
fixInfo: null,
lineNumber: 52,
lineNumber: 51,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
@ -51784,6 +51784,126 @@ Generated by [AVA](https://avajs.dev).
'no-space-in-links',
],
},
{
errorContext: '[ref ]',
errorDetail: null,
errorRange: [
1,
6,
],
fixInfo: {
deleteCount: 4,
editColumn: 2,
insertText: 'ref',
},
lineNumber: 68,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
},
{
errorContext: '[ ref]',
errorDetail: null,
errorRange: [
1,
6,
],
fixInfo: {
deleteCount: 4,
editColumn: 2,
insertText: 'ref',
},
lineNumber: 70,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
},
{
errorContext: '[ ref ]',
errorDetail: null,
errorRange: [
1,
7,
],
fixInfo: {
deleteCount: 5,
editColumn: 2,
insertText: 'ref',
},
lineNumber: 72,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
},
{
errorContext: '[ref ]',
errorDetail: null,
errorRange: [
1,
6,
],
fixInfo: {
deleteCount: 4,
editColumn: 2,
insertText: 'ref',
},
lineNumber: 76,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
},
{
errorContext: '[ ref]',
errorDetail: null,
errorRange: [
1,
6,
],
fixInfo: {
deleteCount: 4,
editColumn: 2,
insertText: 'ref',
},
lineNumber: 78,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
},
{
errorContext: '[ ref ]',
errorDetail: null,
errorRange: [
1,
7,
],
fixInfo: {
deleteCount: 5,
editColumn: 2,
insertText: 'ref',
},
lineNumber: 80,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
},
],
fixed: `# Spaces Inside Link Text␊
@ -51835,8 +51955,8 @@ Generated by [AVA](https://avajs.dev).
[with](spaces) ␊
[error]({MD039})␊
Wrapped [ link with leading space␊
](https://example.com) {MD039}
Wrapped [ link with leading space {MD039}
](https://example.com)␊
Non-wrapped [link with leading space](https://example.com) {MD039}␊
@ -51850,7 +51970,27 @@ Generated by [AVA](https://avajs.dev).
[link][ref] {MD039}␊
[ref]␊
[ref] {MD039}␊
[ref] {MD039}␊
[ref] {MD039}␊
[ref][]␊
[ref][] {MD039}␊
[ref][] {MD039}␊
[ref][] {MD039}␊
[ref]: https://example.com␊
Not a link, just [ text in ] brackets␊
Images are ![ not links ](image.jpg)␊
`,
}

View file

@ -48,8 +48,8 @@ function MoreCodeButNotCode(input) {
[with](spaces)
[error ]({MD039})
Wrapped [ link with leading space
](https://example.com) {MD039}
Wrapped [ link with leading space {MD039}
](https://example.com)
Non-wrapped [ link with leading space](https://example.com) {MD039}
@ -63,4 +63,24 @@ Non-wrapped [ link with leading space](https://example.com) {MD039}
[ link ][ref] {MD039}
[ref]
[ref ] {MD039}
[ ref] {MD039}
[ ref ] {MD039}
[ref][]
[ref ][] {MD039}
[ ref][] {MD039}
[ ref ][] {MD039}
[ref]: https://example.com
Not a link, just [ text in ] brackets
Images are ![ not links ](image.jpg)