Reimplement MD021/no-multiple-space-closed-atx using micromark tokens.

This commit is contained in:
David Anson 2024-06-15 15:45:04 -07:00
parent e3ca9b1755
commit 0b165c1566
8 changed files with 393 additions and 219 deletions

View file

@ -977,3 +977,11 @@ test("endOfLineGemojiCodeRe", async(t) => {
t.true(helpers.endOfLineGemojiCodeRe.test(`-:${emoji}:`), emoji);
}
});
test("ellipsify", (t) => {
t.is(helpers.ellipsify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), "abcdefghijklmnopqrstuvwxyzABCD...");
t.is(helpers.ellipsify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", false, false), "abcdefghijklmnopqrstuvwxyzABCD...");
t.is(helpers.ellipsify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", true, false), "abcdefghijklmnopqrstuvwxyzABCD...");
t.is(helpers.ellipsify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", false, true), "...wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
t.is(helpers.ellipsify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", true, true), "abcdefghijklmno...LMNOPQRSTUVWXYZ");
});

View file

@ -167,8 +167,8 @@ test("resultFormattingV1", (t) => new Promise((resolve) => {
"Multiple spaces inside hashes on closed atx style heading",
"ruleInformation": `${homepage}/blob/v${version}/doc/md021.md`,
"errorDetail": null,
"errorContext": "# Multiple spa...tyle heading #",
"errorRange": [ 1, 4 ] }
"errorContext": "# Multiple spaces inside hash...",
"errorRange": [ 3, 1 ] }
],
"./test/atx_heading_spacing.md": [
{ "lineNumber": 1,
@ -237,7 +237,7 @@ test("resultFormattingV1", (t) => new Promise((resolve) => {
" [Context: \"## Heading\"]\n" +
"truncate: 1: MD021/no-multiple-space-closed-atx" +
" Multiple spaces inside hashes on closed atx style heading" +
" [Context: \"# Multiple spa...tyle heading #\"]";
" [Context: \"# Multiple spaces inside hash...\"]";
t.is(actualMessage, expectedMessage, "Incorrect message.");
resolve();
});
@ -270,8 +270,8 @@ test("resultFormattingV2", (t) => new Promise((resolve) => {
"Multiple spaces inside hashes on closed atx style heading",
"ruleInformation": `${homepage}/blob/v${version}/doc/md021.md`,
"errorDetail": null,
"errorContext": "# Multiple spa...tyle heading #",
"errorRange": [ 1, 4 ] }
"errorContext": "# Multiple spaces inside hash...",
"errorRange": [ 3, 1 ] }
],
"./test/atx_heading_spacing.md": [
{ "lineNumber": 1,
@ -336,7 +336,7 @@ test("resultFormattingV2", (t) => new Promise((resolve) => {
" [Context: \"## Heading\"]\n" +
"truncate: 1: MD021/no-multiple-space-closed-atx" +
" Multiple spaces inside hashes on closed atx style heading" +
" [Context: \"# Multiple spa...tyle heading #\"]";
" [Context: \"# Multiple spaces inside hash...\"]";
t.is(actualMessage, expectedMessage, "Incorrect message.");
resolve();
});

View file

@ -524,13 +524,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Multiple spaces E {MD021} ...',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 32,
editColumn: 1,
insertText: '## Multiple spaces E {MD021} ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 22,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -544,13 +543,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '... Multiple spaces F {MD021} ##',
errorDetail: null,
errorRange: [
28,
5,
30,
1,
],
fixInfo: {
deleteCount: 32,
editColumn: 1,
insertText: '## Multiple spaces F {MD021} ##',
deleteCount: 1,
editColumn: 30,
},
lineNumber: 24,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2701,13 +2699,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 5 {MD021} ##',
errorDetail: null,
errorRange: [
1,
7,
4,
3,
],
fixInfo: {
deleteCount: 28,
editColumn: 1,
insertText: '## Heading 5 {MD021} ##',
deleteCount: 3,
editColumn: 4,
},
lineNumber: 15,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2721,13 +2718,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 6 {MD021} ##',
errorDetail: null,
errorRange: [
20,
6,
22,
2,
],
fixInfo: {
deleteCount: 27,
editColumn: 1,
insertText: '## Heading 6 {MD021} ##',
deleteCount: 2,
editColumn: 22,
},
lineNumber: 17,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2741,13 +2737,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 7 {MD021} ##',
errorDetail: null,
errorRange: [
1,
7,
4,
3,
],
fixInfo: {
deleteCount: 30,
editColumn: 1,
insertText: '## Heading 7 {MD021} ##',
deleteCount: 3,
editColumn: 4,
},
lineNumber: 19,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '## Heading 7 {MD021} ##',
errorDetail: null,
errorRange: [
25,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 25,
},
lineNumber: 19,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2772,11 +2786,11 @@ Generated by [AVA](https://avajs.dev).
## Heading 5 {MD020} ##␊
## Heading 5 {MD021} ##␊
## Heading 5 {MD021} ##
## Heading 6 {MD021} ##␊
## Heading 6 {MD021} ##
## Heading 7 {MD021} ##␊
## Heading 7 {MD021} ##
`,
}
@ -2850,13 +2864,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 4 {MD021} ##',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 24,
editColumn: 1,
insertText: '## Heading 4 {MD021} ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 7,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2870,13 +2883,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 5 {MD021} ##',
errorDetail: null,
errorRange: [
20,
5,
22,
1,
],
fixInfo: {
deleteCount: 24,
editColumn: 1,
insertText: '## Heading 5 {MD021} ##',
deleteCount: 1,
editColumn: 22,
},
lineNumber: 9,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2890,13 +2902,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 6 {MD021} ##',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 25,
editColumn: 1,
insertText: '## Heading 6 {MD021} ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 11,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '## Heading 6 {MD021} ##',
errorDetail: null,
errorRange: [
23,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 23,
},
lineNumber: 11,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -2910,13 +2940,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Heading 7 {MD021} ##',
errorDetail: null,
errorRange: [
1,
6,
4,
2,
],
fixInfo: {
deleteCount: 27,
editColumn: 1,
insertText: '## Heading 7 {MD021} ##',
deleteCount: 2,
editColumn: 4,
},
lineNumber: 13,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '## Heading 7 {MD021} ##',
errorDetail: null,
errorRange: [
24,
2,
],
fixInfo: {
deleteCount: 2,
editColumn: 24,
},
lineNumber: 13,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -7035,16 +7083,34 @@ Generated by [AVA](https://avajs.dev).
],
},
{
errorContext: '# Heading 7 {M...021} {MD003} #',
errorContext: '# Heading 7 {MD021} {MD003} ...',
errorDetail: null,
errorRange: [
3,
1,
4,
],
fixInfo: {
deleteCount: 31,
editColumn: 1,
insertText: '# Heading 7 {MD021} {MD003} #',
deleteCount: 1,
editColumn: 3,
},
lineNumber: 31,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '... Heading 7 {MD021} {MD003} #',
errorDetail: null,
errorRange: [
30,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 30,
},
lineNumber: 31,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -15927,16 +15993,34 @@ Generated by [AVA](https://avajs.dev).
],
},
{
errorContext: '## Extra Norma...th) {MD021} ##',
errorContext: '## Extra Normal space (both) ...',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 41,
editColumn: 1,
insertText: '## Extra Normal space (both) {MD021} ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 29,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '...ormal space (both) {MD021} ##',
errorDetail: null,
errorRange: [
39,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 39,
},
lineNumber: 29,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -15950,13 +16034,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## Extra tab (left) {MD021} #...',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 31,
editColumn: 1,
insertText: '## Extra tab (left) {MD021} ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 33,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -15970,13 +16053,12 @@ Generated by [AVA](https://avajs.dev).
errorContext: '... Extra tab (right) {MD021} ##',
errorDetail: null,
errorRange: [
28,
5,
30,
1,
],
fixInfo: {
deleteCount: 32,
editColumn: 1,
insertText: '## Extra tab (right) {MD021} ##',
deleteCount: 1,
editColumn: 30,
},
lineNumber: 37,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -16019,11 +16101,11 @@ Generated by [AVA](https://avajs.dev).
##   Extra non-breaking space (left) {MD020} ##␊
## Extra tab (left) {MD021} ##␊
## Extra tab (left) {MD021} ##␊
## Extra non-breaking space (right) {MD020}   ##␊
## Extra tab (right) {MD021} ##␊
## Extra tab (right) {MD021} ##␊
<!-- markdownlint-configure-file {␊
"heading-style": false,␊
@ -38011,16 +38093,34 @@ Generated by [AVA](https://avajs.dev).
],
},
{
errorContext: '### Heading 3b...1} {MD022} ###',
errorContext: '### Heading 3b {MD003} {MD021...',
errorDetail: null,
errorRange: [
5,
1,
6,
],
fixInfo: {
deleteCount: 44,
editColumn: 1,
insertText: '### Heading 3b {MD003} {MD021} {MD022} ###',
deleteCount: 1,
editColumn: 5,
},
lineNumber: 32,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '...b {MD003} {MD021} {MD022} ###',
errorDetail: null,
errorRange: [
41,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 41,
},
lineNumber: 32,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -46848,13 +46948,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '# F #',
errorDetail: null,
errorRange: [
3,
1,
4,
],
fixInfo: {
deleteCount: 7,
editColumn: 1,
insertText: '# F #',
deleteCount: 1,
editColumn: 3,
},
lineNumber: 21,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '# F #',
errorDetail: null,
errorRange: [
6,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 6,
},
lineNumber: 21,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -46868,13 +46986,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## L ##',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 9,
editColumn: 1,
insertText: '## L ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 41,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '## L ##',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 41,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -46888,13 +47024,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '# RR #',
errorDetail: null,
errorRange: [
3,
1,
4,
],
fixInfo: {
deleteCount: 8,
editColumn: 1,
insertText: '# RR #',
deleteCount: 1,
editColumn: 3,
},
lineNumber: 61,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '# RR #',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 61,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
@ -46908,13 +47062,31 @@ Generated by [AVA](https://avajs.dev).
errorContext: '## XX ##',
errorDetail: null,
errorRange: [
4,
1,
5,
],
fixInfo: {
deleteCount: 10,
editColumn: 1,
insertText: '## XX ##',
deleteCount: 1,
editColumn: 4,
},
lineNumber: 81,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md021.md',
ruleNames: [
'MD021',
'no-multiple-space-closed-atx',
],
},
{
errorContext: '## XX ##',
errorDetail: null,
errorRange: [
8,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 8,
},
lineNumber: 81,
ruleDescription: 'Multiple spaces inside hashes on closed atx style heading',