mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add "sublist" style to MD004 (fixes #21).
This commit is contained in:
parent
c8ecec1953
commit
7a1773ea77
4 changed files with 91 additions and 7 deletions
19
doc/Rules.md
19
doc/Rules.md
|
@ -98,7 +98,8 @@ Tags: bullet, ul
|
||||||
|
|
||||||
Aliases: ul-style
|
Aliases: ul-style
|
||||||
|
|
||||||
Parameters: style ("consistent", "asterisk", "plus", "dash"; default "consistent")
|
Parameters: style ("consistent", "asterisk", "plus", "dash", "sublist"; default
|
||||||
|
"consistent")
|
||||||
|
|
||||||
This rule is triggered when the symbols used in the document for unordered
|
This rule is triggered when the symbols used in the document for unordered
|
||||||
list items do not match the configured unordered list style:
|
list items do not match the configured unordered list style:
|
||||||
|
@ -114,9 +115,19 @@ document:
|
||||||
* Item 2
|
* Item 2
|
||||||
* Item 3
|
* Item 3
|
||||||
|
|
||||||
Note: the configured list style can be a specific symbol to use (asterisk,
|
The configured list style can be a specific symbol to use (asterisk, plus, dash),
|
||||||
plus, dash), or simply require that the usage be consistent within the
|
can require that usage be consistent within the document, or can require that each
|
||||||
document.
|
sublist have a consistent symbol that is different from its parent list.
|
||||||
|
|
||||||
|
For example, the following is valid for the `sublist` style because the outer-most
|
||||||
|
indent uses asterisk, the middle indent uses plus, and the inner-most indent uses dash:
|
||||||
|
|
||||||
|
* Item 1
|
||||||
|
+ Item 2
|
||||||
|
- Item 3
|
||||||
|
+ Item 4
|
||||||
|
* Item 4
|
||||||
|
+ Item 5
|
||||||
|
|
||||||
## MD005 - Inconsistent indentation for list items at the same level
|
## MD005 - Inconsistent indentation for list items at the same level
|
||||||
|
|
||||||
|
|
17
lib/rules.js
17
lib/rules.js
|
@ -224,13 +224,24 @@ module.exports = [
|
||||||
"aliases": [ "ul-style" ],
|
"aliases": [ "ul-style" ],
|
||||||
"func": function MD004(params, errors) {
|
"func": function MD004(params, errors) {
|
||||||
var style = params.options.style || "consistent";
|
var style = params.options.style || "consistent";
|
||||||
|
var expectedStyle = style;
|
||||||
|
var nestingStyles = [];
|
||||||
flattenLists(params).forEach(function forList(list) {
|
flattenLists(params).forEach(function forList(list) {
|
||||||
if (list.unordered) {
|
if (list.unordered) {
|
||||||
if (style === "consistent") {
|
if (expectedStyle === "consistent") {
|
||||||
style = unorderedListStyleFor(list.items[0]);
|
expectedStyle = unorderedListStyleFor(list.items[0]);
|
||||||
}
|
}
|
||||||
list.items.forEach(function forItem(item) {
|
list.items.forEach(function forItem(item) {
|
||||||
if (unorderedListStyleFor(item) !== style) {
|
var itemStyle = unorderedListStyleFor(item);
|
||||||
|
if (style === "sublist") {
|
||||||
|
var nesting = list.nesting;
|
||||||
|
if (!nestingStyles[nesting] &&
|
||||||
|
(itemStyle !== nestingStyles[nesting - 1])) {
|
||||||
|
nestingStyles[nesting] = itemStyle;
|
||||||
|
} else if (itemStyle !== nestingStyles[nesting]) {
|
||||||
|
errors.push(item.lineNumber);
|
||||||
|
}
|
||||||
|
} else if (itemStyle !== expectedStyle) {
|
||||||
errors.push(item.lineNumber);
|
errors.push(item.lineNumber);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
6
test/sublist-bullet-style.json
Normal file
6
test/sublist-bullet-style.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD004": {
|
||||||
|
"style": "sublist"
|
||||||
|
}
|
||||||
|
}
|
56
test/sublist-bullet-style.md
Normal file
56
test/sublist-bullet-style.md
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
1. item
|
||||||
|
1. item
|
||||||
|
+ item
|
||||||
|
1. item
|
||||||
|
- item {MD004}
|
||||||
|
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
+ item
|
||||||
|
- item
|
||||||
|
+ item
|
||||||
|
* item
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
+ item
|
||||||
|
- item
|
||||||
|
|
||||||
|
+ item {MD004}
|
||||||
|
+ item {MD004}
|
||||||
|
+ item
|
||||||
|
+ item {MD004}
|
||||||
|
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
* item {MD004}
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
|
||||||
|
+ item {MD004}
|
||||||
|
- item {MD004}
|
||||||
|
* item {MD004}
|
||||||
|
|
||||||
|
- item
|
||||||
|
1. item
|
||||||
|
+ item
|
||||||
|
1. item
|
||||||
|
* item
|
||||||
|
|
||||||
|
1. item
|
||||||
|
* item
|
||||||
|
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
+ item
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
* item {MD004}
|
||||||
|
+ item
|
||||||
|
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
+ item
|
||||||
|
- item
|
||||||
|
* item
|
||||||
|
- item {MD004}
|
||||||
|
+ item
|
Loading…
Add table
Add a link
Reference in a new issue