mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add MD037 with tests, improve handling of line numbers for inlines.
This commit is contained in:
parent
bd7e712728
commit
b85e53a9c4
6 changed files with 108 additions and 21 deletions
47
lib/rules.js
47
lib/rules.js
|
|
@ -60,6 +60,15 @@ function forEachLine(params, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
// Calls the provided function for each text token
|
||||
function forEachText(params, callback) {
|
||||
filterTokens(params.tokens, "inline")
|
||||
.forEach(function forToken(token) {
|
||||
filterTokens(token.children, "text")
|
||||
.forEach(callback);
|
||||
});
|
||||
}
|
||||
|
||||
// Calls the provided function for each heading's content
|
||||
function forEachHeading(params, callback) {
|
||||
var heading = null;
|
||||
|
|
@ -266,15 +275,11 @@ module.exports = [
|
|||
"desc": "Reversed link syntax",
|
||||
"tags": [ "links" ],
|
||||
"func": function MD011(params, errors) {
|
||||
filterTokens(params.tokens, "inline")
|
||||
.forEach(function forToken(token) {
|
||||
filterTokens(token.children, "text")
|
||||
.forEach(function forChild(child) {
|
||||
if (/\([^)]+\)\[[^\]]+\]/.test(child.content)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
});
|
||||
forEachText(params, function forToken(token) {
|
||||
if (/\([^)]+\)\[[^\]]+\]/.test(token.content)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -631,7 +636,6 @@ module.exports = [
|
|||
"func": function MD034(params, errors) {
|
||||
filterTokens(params.tokens, "inline")
|
||||
.forEach(function forToken(token) {
|
||||
var lineNumber = token.lineNumber;
|
||||
var inLink = false;
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type === "link_open") {
|
||||
|
|
@ -641,10 +645,7 @@ module.exports = [
|
|||
} else if ((child.type === "text") &&
|
||||
!inLink &&
|
||||
/https?:\/\//.test(child.content)) {
|
||||
errors.push(lineNumber);
|
||||
} else if ((child.type === "softbreak") ||
|
||||
(child.type === "hardbreak")) {
|
||||
lineNumber++;
|
||||
errors.push(child.lineNumber);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -674,9 +675,7 @@ module.exports = [
|
|||
"desc": "Emphasis used instead of a header",
|
||||
"tags": [ "headers", "emphasis" ],
|
||||
"func": function MD036(params, errors) {
|
||||
var lineNumber = 0;
|
||||
function base(token) {
|
||||
lineNumber = token.lineNumber;
|
||||
if (token.type === "paragraph_open") {
|
||||
return function inParagraph(t) {
|
||||
if ((t.type === "inline") &&
|
||||
|
|
@ -684,7 +683,7 @@ module.exports = [
|
|||
((t.children[0].type === "strong_open") ||
|
||||
(t.children[0].type === "em_open")) &&
|
||||
(t.children[1].type === "text")) {
|
||||
errors.push(lineNumber);
|
||||
errors.push(t.lineNumber);
|
||||
}
|
||||
};
|
||||
} else if (token.type === "blockquote_open") {
|
||||
|
|
@ -700,5 +699,19 @@ module.exports = [
|
|||
state = state(token) || base;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD037",
|
||||
"desc": "Spaces inside emphasis markers",
|
||||
"tags": [ "whitespace", "emphasis" ],
|
||||
"func": function MD037(params, errors) {
|
||||
forEachText(params, function forToken(token) {
|
||||
if (/\s(\*\*?|__?)\s.+\1/.test(token.content) ||
|
||||
/(\*\*?|__?).+\s\1\s/.test(token.content)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue