Update MD022/blanks-around-headings to allow specifying a different number of blank lines for each heading level (fixes #504).

This commit is contained in:
David Anson 2023-08-08 22:56:47 -07:00
parent bdc9d357f3
commit d9de1dd22f
13 changed files with 690 additions and 64 deletions

View file

@ -0,0 +1,127 @@
# Blanks Around Headings (Arrays)
# Apple - Good
Text
# Apple - Top {MD022}
Text
# Apple - Bottom
Text
## Banana - Good
Text
## Banana - Top {MD022}
Text
## Banana - Bottom {MD022}
Text
### Cherry - Good
Text
### Cherry - Top {MD022}
Text
### Cherry - Bottom {MD022}
Text
#### Durian - Good ####
Text
#### Durian - Top ####
Text
#### Durian - Bottom {MD022} ####
Text
##### Elderberry - Good
Text
##### Elderberry - Top {MD022}
Text
##### Elderberry - Bottom
Text
###### Fig - Good ######
Text
###### Fig - Top {MD022} ######
Text
###### Fig - Bottom {MD022} ######
Text
Grape - Good
============
---
Grape - Top {MD022}
===================
Text
Grape - Bottom
==============
Text
Honeycomb - Good
---------
Text
Honeycomb - Top {MD022}
-----------------------
Text
Honeycomb - Bottom {MD022}
--------------------------
Text
<!-- markdownlint-configure-file {
"heading-style": false,
"no-multiple-blanks": false,
"single-title": false,
"blanks-around-headings": {
"lines_above": [ 1, 2, 3, -1],
"lines_below": [ -1, 2, 1, 3, -1, 4, 10 ]
}
} -->

View file

@ -919,7 +919,7 @@ test("readme", (t) => new Promise((resolve) => {
}));
test("validateJsonUsingConfigSchemaStrict", (t) => {
t.plan(158);
t.plan(159);
const configRe =
/^[\s\S]*<!-- markdownlint-configure-file ([\s\S]*) -->[\s\S]*$/;
const ignoreFiles = new Set([

View file

@ -4466,6 +4466,370 @@ Generated by [AVA](https://avajs.dev).
`,
}
## blanks-around-headings-arrays.md
> Snapshot 1
{
errors: [
{
errorContext: '# Apple - Top {MD022}',
errorDetail: 'Expected: 1; Actual: 0; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 5,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '## Banana - Top {MD022}',
errorDetail: 'Expected: 2; Actual: 1; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 18,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '## Banana - Bottom {MD022}',
errorDetail: 'Expected: 2; Actual: 1; Below',
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 25,
},
lineNumber: 24,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '### Cherry - Top {MD022}',
errorDetail: 'Expected: 3; Actual: 2; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 35,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '### Cherry - Bottom {MD022}',
errorDetail: 'Expected: 1; Actual: 0; Below',
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 42,
},
lineNumber: 41,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '#### Durian - Bottom {MD022} ####',
errorDetail: 'Expected: 3; Actual: 1; Below',
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 55,
},
lineNumber: 54,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '##### Elderberry - Top {MD022}',
errorDetail: 'Expected: 1; Actual: 0; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 61,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '###### Fig - Top {MD022} ######',
errorDetail: 'Expected: 1; Actual: 0; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 74,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: '###### Fig - Bottom {MD022} ######',
errorDetail: 'Expected: 4; Actual: 1; Below',
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 82,
},
lineNumber: 81,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: 'Grape - Top {MD022}',
errorDetail: 'Expected: 1; Actual: 0; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 89,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: 'Honeycomb - Top {MD022}',
errorDetail: 'Expected: 2; Actual: 1; Above',
errorRange: null,
fixInfo: {
insertText: `␊
`,
},
lineNumber: 107,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
{
errorContext: 'Honeycomb - Bottom {MD022}',
errorDetail: 'Expected: 2; Actual: 1; Below',
errorRange: null,
fixInfo: {
insertText: `␊
`,
lineNumber: 116,
},
lineNumber: 114,
ruleDescription: 'Headings should be surrounded by blank lines',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md022.md',
ruleNames: [
'MD022',
'blanks-around-headings',
'blanks-around-headers',
],
},
],
fixed: `# Blanks Around Headings (Arrays)␊
# Apple - Good␊
Text␊
# Apple - Top {MD022}␊
Text␊
# Apple - Bottom␊
Text␊
## Banana - Good␊
Text␊
## Banana - Top {MD022}␊
Text␊
## Banana - Bottom {MD022}␊
Text␊
### Cherry - Good␊
Text␊
### Cherry - Top {MD022}␊
Text␊
### Cherry - Bottom {MD022}␊
Text␊
#### Durian - Good ####␊
Text␊
#### Durian - Top ####␊
Text␊
#### Durian - Bottom {MD022} ####␊
Text␊
##### Elderberry - Good␊
Text␊
##### Elderberry - Top {MD022}␊
Text␊
##### Elderberry - Bottom␊
Text␊
###### Fig - Good ######␊
Text␊
###### Fig - Top {MD022} ######␊
Text␊
###### Fig - Bottom {MD022} ######␊
Text␊
Grape - Good␊
============␊
---␊
Grape - Top {MD022}␊
===================␊
Text␊
Grape - Bottom␊
==============␊
Text␊
Honeycomb - Good␊
---------␊
Text␊
Honeycomb - Top {MD022}␊
-----------------------␊
Text␊
Honeycomb - Bottom {MD022}␊
--------------------------␊
Text␊
<!-- markdownlint-configure-file {␊
"heading-style": false,␊
"no-multiple-blanks": false,␊
"single-title": false,␊
"blanks-around-headings": {␊
"lines_above": [ 1, 2, 3, -1],␊
"lines_below": [ -1, 2, 1, 3, -1, 4, 10 ]␊
}␊
} -->␊
`,
}
## blanks-around-headings.md
> Snapshot 1