mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01: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;
|
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) {
|
function headingStyleFrom(token, lines) {
|
||||||
if ((token.lines[1] - token.lines[0]) === 1) {
|
if ((token.lines[1] - token.lines[0]) === 1) {
|
||||||
if (lines[token.lines[0]].match(/#\s*$/)) {
|
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",
|
"name": "MD031",
|
||||||
"desc": "Fenced code blocks should be surrounded by blank lines",
|
"desc": "Fenced code blocks should be surrounded by blank lines",
|
||||||
|
|
|
||||||
6
test/bulleted_list_2_space_indent.json
Normal file
6
test/bulleted_list_2_space_indent.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD007": {
|
||||||
|
"indent": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
6
test/bulleted_list_2_space_indent.md
Normal file
6
test/bulleted_list_2_space_indent.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
This is a document where the lists are indented by 2 spaces, but the style is
|
||||||
|
set to 4 space indents for lists:
|
||||||
|
|
||||||
|
* Test X
|
||||||
|
* Test Y {MD007}
|
||||||
|
* Test Z {MD007}
|
||||||
3
test/bulleted_list_4_space_indent.md
Normal file
3
test/bulleted_list_4_space_indent.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
* Test X
|
||||||
|
* Test Y {MD007}
|
||||||
|
* Test Z {MD007}
|
||||||
4
test/inconsistent_bullet_indent_same_level.md
Normal file
4
test/inconsistent_bullet_indent_same_level.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
* Item
|
||||||
|
* Item {MD007}
|
||||||
|
* Item {MD005}
|
||||||
|
* Item
|
||||||
Loading…
Add table
Add a link
Reference in a new issue