Add MD018, MD019 with tests, switch to RegExp.test.

This commit is contained in:
David Anson 2015-03-06 09:21:55 -08:00
parent 62314e61b1
commit d0fcd32f3a
3 changed files with 45 additions and 10 deletions

View file

@ -6,7 +6,7 @@ function indentFor(token) {
function headingStyleFor(token) {
if ((token.lines[1] - token.lines[0]) === 1) {
if (token.line.match(/#\s*$/)) {
if (/#\s*$/.test(token.line)) {
return "atx_closed";
}
return "atx";
@ -174,7 +174,7 @@ module.exports = [
"desc": "Trailing spaces",
"func": function MD009(params, errors) {
params.lines.forEach(function forLine(line, lineIndex) {
if (line.match(/\s$/)) {
if (/\s$/.test(line)) {
errors.push(lineIndex + 1);
}
});
@ -186,7 +186,7 @@ module.exports = [
"desc": "Hard tabs",
"func": function MD010(params, errors) {
params.lines.forEach(function forLine(line, lineIndex) {
if (line.match(/\t/)) {
if (/\t/.test(line)) {
errors.push(lineIndex + 1);
}
});
@ -201,7 +201,7 @@ module.exports = [
.forEach(function forToken(token) {
filterTokens(token.children, "text")
.forEach(function forChild(child) {
if (child.content.match(/\([^)]+\)\[[^\]]+\]/)) {
if (/\([^)]+\)\[[^\]]+\]/.test(child.content)) {
errors.push(token.lineNumber);
}
});
@ -259,7 +259,33 @@ module.exports = [
}).every(function forLine(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 inCode = false;
lines.forEach(function forLine(line, lineNumber) {
if (line.match(/^(```|~~~)/)) {
if (/^(```|~~~)/.test(line)) {
inCode = !inCode;
if ((inCode && lines[lineNumber - 1].length) ||
(!inCode && lines[lineNumber + 1].length)) {
@ -311,15 +337,15 @@ module.exports = [
var prevLine = "";
params.lines.forEach(function forLine(line, lineIndex) {
if (!inCode) {
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
var listMarker = /^([\*\+\-]|(\d+\.))\s/.test(line.trim());
if (listMarker && !inList && !/^($|\s)/.test(prevLine)) {
errors.push(lineIndex + 1);
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
} else if (!listMarker && inList && !/^($|\s)/.test(line)) {
errors.push(lineIndex);
}
inList = listMarker;
}
if (line.trim().match(/^(```|~~~)/)) {
if (/^(```|~~~)/.test(line.trim())) {
inCode = !inCode;
inList = false;
}

View file

@ -0,0 +1,4 @@
{
"default": true,
"MD002": false
}

View file

@ -0,0 +1,5 @@
#Header 1 {MD018}
## Header 2 {MD019}
## Header 3 {MD019}