mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add MD005, MD007 with tests.
This commit is contained in:
parent
5d9b32e8dc
commit
9eb3eb9083
5 changed files with 63 additions and 0 deletions
44
lib/rules.js
44
lib/rules.js
|
@ -4,6 +4,11 @@ function lineNumberFrom(token) {
|
|||
return token.lines[0] + 1;
|
||||
}
|
||||
|
||||
function indentFrom(token, lines) {
|
||||
var line = lines[token.lines[0]];
|
||||
return line.length - line.trimLeft().length;
|
||||
}
|
||||
|
||||
function headingStyleFrom(token, lines) {
|
||||
if ((token.lines[1] - token.lines[0]) === 1) {
|
||||
if (lines[token.lines[0]].match(/#\s*$/)) {
|
||||
|
@ -107,6 +112,45 @@ module.exports = [
|
|||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD005",
|
||||
"desc": "Inconsistent indentation for list items at the same level",
|
||||
"func": function MD005(params, errors) {
|
||||
var listItems = params.tokens.filter(function filterToken(token) {
|
||||
return (token.type === "list_item_open");
|
||||
});
|
||||
var indentLevels = [];
|
||||
listItems.forEach(function forToken(token) {
|
||||
var indentLevel = indentFrom(token, params.lines);
|
||||
if (!indentLevels[token.level]) {
|
||||
indentLevels[token.level] = indentLevel;
|
||||
} else if (indentLevel !== indentLevels[token.level]) {
|
||||
errors.push(lineNumberFrom(token));
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD007",
|
||||
"desc": "Unordered list indentation",
|
||||
"func": function MD007(params, errors) {
|
||||
var optionsIndent = params.options.indent || 2;
|
||||
var bulletLists = params.tokens.filter(function filterToken(token) {
|
||||
return (token.type === "bullet_list_open");
|
||||
});
|
||||
var prevIndent = 0;
|
||||
bulletLists.forEach(function forToken(token) {
|
||||
var indent = indentFrom(token, params.lines);
|
||||
if ((indent > prevIndent) &&
|
||||
((indent - prevIndent) !== optionsIndent)) {
|
||||
errors.push(lineNumberFrom(token));
|
||||
}
|
||||
prevIndent = indent;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD031",
|
||||
"desc": "Fenced code blocks should be surrounded by blank lines",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue