Update MD043 to fix required header checks in middle and last when using special char "*" (#396)

This commit is contained in:
Jeremy Suriel 2021-05-20 15:45:27 -04:00 committed by GitHub
parent 9122b8d935
commit c6d95cb904
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 6 deletions

View file

@ -3703,8 +3703,11 @@ module.exports = {
var actual = levels_1[heading.tag] + " " + content; var actual = levels_1[heading.tag] + " " + content;
var expected = getExpected_1(); var expected = getExpected_1();
if (expected === "*") { if (expected === "*") {
matchAny_1 = true; var nextExpected = getExpected_1();
getExpected_1(); if (nextExpected.toLowerCase() !== actual.toLowerCase()) {
matchAny_1 = true;
i_1--;
}
} }
else if (expected === "+") { else if (expected === "+") {
matchAny_1 = true; matchAny_1 = true;
@ -3721,8 +3724,10 @@ module.exports = {
} }
} }
}); });
var extraHeadings = requiredHeadings.length - i_1;
if (!hasError_1 && if (!hasError_1 &&
(i_1 < requiredHeadings.length) && ((extraHeadings > 1) ||
((extraHeadings === 1) && (requiredHeadings[i_1] !== "*"))) &&
(anyHeadings_1 || !requiredHeadings.every(function (heading) { return heading === "*"; }))) { (anyHeadings_1 || !requiredHeadings.every(function (heading) { return heading === "*"; }))) {
addErrorContext(onError, params.lines.length, requiredHeadings[i_1]); addErrorContext(onError, params.lines.length, requiredHeadings[i_1]);
} }

View file

@ -28,8 +28,11 @@ module.exports = {
const actual = levels[heading.tag] + " " + content; const actual = levels[heading.tag] + " " + content;
const expected = getExpected(); const expected = getExpected();
if (expected === "*") { if (expected === "*") {
matchAny = true; const nextExpected = getExpected();
getExpected(); if (nextExpected.toLowerCase() !== actual.toLowerCase()) {
matchAny = true;
i--;
}
} else if (expected === "+") { } else if (expected === "+") {
matchAny = true; matchAny = true;
} else if (expected.toLowerCase() === actual.toLowerCase()) { } else if (expected.toLowerCase() === actual.toLowerCase()) {
@ -43,9 +46,11 @@ module.exports = {
} }
} }
}); });
const extraHeadings = requiredHeadings.length - i;
if ( if (
!hasError && !hasError &&
(i < requiredHeadings.length) && ((extraHeadings > 1) ||
((extraHeadings === 1) && (requiredHeadings[i] !== "*"))) &&
(anyHeadings || !requiredHeadings.every((heading) => heading === "*")) (anyHeadings || !requiredHeadings.every((heading) => heading === "*"))
) { ) {
addErrorContext(onError, params.lines.length, addErrorContext(onError, params.lines.length,

View file

@ -0,0 +1,14 @@
{
"default": true,
"MD043": {
"headings": [
"# One",
"*",
"### Three",
"*",
"### Five",
"*",
"#### FOO"
]
}
}

View file

@ -0,0 +1,15 @@
# One
## Two
### THREE
## four
## Five
### SiX
#### FOO
{MD043:16}

View file

@ -0,0 +1,14 @@
{
"default": true,
"MD043": {
"headings": [
"# One",
"*",
"### Three",
"*",
"### FOO",
"*",
"#### 7"
]
}
}

View file

@ -0,0 +1,15 @@
# One
## Two
### THREE
## four
## Five
### SiX
#### 7
{MD043:16}

View file

@ -0,0 +1,11 @@
{
"default": true,
"MD043": {
"headings": [
"# One",
"## Two",
"### Three",
"*"
]
}
}

View file

@ -0,0 +1,5 @@
# One
## Two
### THREE