mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Add MD018, MD019 with tests, switch to RegExp.test.
This commit is contained in:
parent
62314e61b1
commit
d0fcd32f3a
3 changed files with 45 additions and 10 deletions
46
lib/rules.js
46
lib/rules.js
|
|
@ -6,7 +6,7 @@ function indentFor(token) {
|
||||||
|
|
||||||
function headingStyleFor(token) {
|
function headingStyleFor(token) {
|
||||||
if ((token.lines[1] - token.lines[0]) === 1) {
|
if ((token.lines[1] - token.lines[0]) === 1) {
|
||||||
if (token.line.match(/#\s*$/)) {
|
if (/#\s*$/.test(token.line)) {
|
||||||
return "atx_closed";
|
return "atx_closed";
|
||||||
}
|
}
|
||||||
return "atx";
|
return "atx";
|
||||||
|
|
@ -174,7 +174,7 @@ module.exports = [
|
||||||
"desc": "Trailing spaces",
|
"desc": "Trailing spaces",
|
||||||
"func": function MD009(params, errors) {
|
"func": function MD009(params, errors) {
|
||||||
params.lines.forEach(function forLine(line, lineIndex) {
|
params.lines.forEach(function forLine(line, lineIndex) {
|
||||||
if (line.match(/\s$/)) {
|
if (/\s$/.test(line)) {
|
||||||
errors.push(lineIndex + 1);
|
errors.push(lineIndex + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -186,7 +186,7 @@ module.exports = [
|
||||||
"desc": "Hard tabs",
|
"desc": "Hard tabs",
|
||||||
"func": function MD010(params, errors) {
|
"func": function MD010(params, errors) {
|
||||||
params.lines.forEach(function forLine(line, lineIndex) {
|
params.lines.forEach(function forLine(line, lineIndex) {
|
||||||
if (line.match(/\t/)) {
|
if (/\t/.test(line)) {
|
||||||
errors.push(lineIndex + 1);
|
errors.push(lineIndex + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -201,7 +201,7 @@ module.exports = [
|
||||||
.forEach(function forToken(token) {
|
.forEach(function forToken(token) {
|
||||||
filterTokens(token.children, "text")
|
filterTokens(token.children, "text")
|
||||||
.forEach(function forChild(child) {
|
.forEach(function forChild(child) {
|
||||||
if (child.content.match(/\([^)]+\)\[[^\]]+\]/)) {
|
if (/\([^)]+\)\[[^\]]+\]/.test(child.content)) {
|
||||||
errors.push(token.lineNumber);
|
errors.push(token.lineNumber);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -259,7 +259,33 @@ module.exports = [
|
||||||
}).every(function forLine(line) {
|
}).every(function forLine(line) {
|
||||||
return /^\$\s/.test(line);
|
return /^\$\s/.test(line);
|
||||||
})) {
|
})) {
|
||||||
errors.push(token.lines[0] + 1);
|
errors.push(token.lineNumber);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD018",
|
||||||
|
"desc": "No space after hash on atx style header",
|
||||||
|
"func": function MD018(params, errors) {
|
||||||
|
params.lines.forEach(function forLine(line, lineIndex) {
|
||||||
|
if (/^#+[^#\s]/.test(line)) {
|
||||||
|
errors.push(lineIndex + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD019",
|
||||||
|
"desc": "Multiple spaces after hash on atx style header",
|
||||||
|
"func": function MD019(params, errors) {
|
||||||
|
filterTokens(params.tokens, "heading_open")
|
||||||
|
.forEach(function forToken(token) {
|
||||||
|
if ((headingStyleFor(token) === "atx") &&
|
||||||
|
/^#+\s\s/.test(token.line)) {
|
||||||
|
errors.push(token.lineNumber);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -289,7 +315,7 @@ module.exports = [
|
||||||
var lines = padAndTrim(params.lines);
|
var lines = padAndTrim(params.lines);
|
||||||
var inCode = false;
|
var inCode = false;
|
||||||
lines.forEach(function forLine(line, lineNumber) {
|
lines.forEach(function forLine(line, lineNumber) {
|
||||||
if (line.match(/^(```|~~~)/)) {
|
if (/^(```|~~~)/.test(line)) {
|
||||||
inCode = !inCode;
|
inCode = !inCode;
|
||||||
if ((inCode && lines[lineNumber - 1].length) ||
|
if ((inCode && lines[lineNumber - 1].length) ||
|
||||||
(!inCode && lines[lineNumber + 1].length)) {
|
(!inCode && lines[lineNumber + 1].length)) {
|
||||||
|
|
@ -311,15 +337,15 @@ module.exports = [
|
||||||
var prevLine = "";
|
var prevLine = "";
|
||||||
params.lines.forEach(function forLine(line, lineIndex) {
|
params.lines.forEach(function forLine(line, lineIndex) {
|
||||||
if (!inCode) {
|
if (!inCode) {
|
||||||
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
|
var listMarker = /^([\*\+\-]|(\d+\.))\s/.test(line.trim());
|
||||||
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
|
if (listMarker && !inList && !/^($|\s)/.test(prevLine)) {
|
||||||
errors.push(lineIndex + 1);
|
errors.push(lineIndex + 1);
|
||||||
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
|
} else if (!listMarker && inList && !/^($|\s)/.test(line)) {
|
||||||
errors.push(lineIndex);
|
errors.push(lineIndex);
|
||||||
}
|
}
|
||||||
inList = listMarker;
|
inList = listMarker;
|
||||||
}
|
}
|
||||||
if (line.trim().match(/^(```|~~~)/)) {
|
if (/^(```|~~~)/.test(line.trim())) {
|
||||||
inCode = !inCode;
|
inCode = !inCode;
|
||||||
inList = false;
|
inList = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
test/atx_header_spacing.json
Normal file
4
test/atx_header_spacing.json
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD002": false
|
||||||
|
}
|
||||||
5
test/atx_header_spacing.md
Normal file
5
test/atx_header_spacing.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#Header 1 {MD018}
|
||||||
|
|
||||||
|
## Header 2 {MD019}
|
||||||
|
|
||||||
|
## Header 3 {MD019}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue