Skip to content

Commit e708a1c

Browse files
committed
Fix list-item-indent for non-incremented lists
Closes GH-40.
1 parent a95b422 commit e708a1c

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

lib/rules/list-item-indent.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,17 @@ function listItemIndent(ast, file, preferred, done) {
9393

9494
visit(ast, 'list', function (node) {
9595
var items = node.children;
96-
var isOrdered = node.ordered;
97-
var offset = node.start || 1;
9896

9997
if (position.generated(node)) {
10098
return;
10199
}
102100

103-
items.forEach(function (item, index) {
101+
items.forEach(function (item) {
104102
var head = item.children[0];
105-
var bulletSize = isOrdered ? String(offset + index).length + 1 : 1;
106-
var tab = Math.ceil(bulletSize / 4) * 4;
107103
var initial = start(item).offset;
108104
var final = start(head).offset;
105+
var bulletSize;
106+
var tab;
109107
var marker;
110108
var shouldBe;
111109
var diff;
@@ -119,6 +117,9 @@ function listItemIndent(ast, file, preferred, done) {
119117

120118
marker = marker.replace(/\[[x ]?\]\s*$/i, '');
121119

120+
bulletSize = marker.trimRight().length;
121+
tab = Math.ceil(bulletSize / 4) * 4;
122+
122123
if (preferred === 'tab-size') {
123124
shouldBe = tab;
124125
} else if (preferred === 'space') {

test/fixtures/list-item-indent-space.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,16 @@ And an extra test for numbers:
4848

4949
11. baz
5050
3
51+
52+
And many items:
53+
54+
1. One
55+
1. Two
56+
1. Three
57+
1. Four
58+
1. Five
59+
1. Six
60+
1. Seven
61+
1. Eight
62+
1. Nine
63+
1. Ten

test/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,17 @@ describe('Rules', function () {
12971297
'list-item-indent-space.md:29:4: Incorrect list-item indent: add 1 space',
12981298
'list-item-indent-space.md:32:4: Incorrect list-item indent: add 1 space',
12991299
'list-item-indent-space.md:37:4: Incorrect list-item indent: add 1 space',
1300-
'list-item-indent-space.md:43:4: Incorrect list-item indent: add 1 space'
1300+
'list-item-indent-space.md:43:4: Incorrect list-item indent: add 1 space',
1301+
'list-item-indent-space.md:54:4: Incorrect list-item indent: add 1 space',
1302+
'list-item-indent-space.md:55:4: Incorrect list-item indent: add 1 space',
1303+
'list-item-indent-space.md:56:4: Incorrect list-item indent: add 1 space',
1304+
'list-item-indent-space.md:57:4: Incorrect list-item indent: add 1 space',
1305+
'list-item-indent-space.md:58:4: Incorrect list-item indent: add 1 space',
1306+
'list-item-indent-space.md:59:4: Incorrect list-item indent: add 1 space',
1307+
'list-item-indent-space.md:60:4: Incorrect list-item indent: add 1 space',
1308+
'list-item-indent-space.md:61:4: Incorrect list-item indent: add 1 space',
1309+
'list-item-indent-space.md:62:4: Incorrect list-item indent: add 1 space',
1310+
'list-item-indent-space.md:63:4: Incorrect list-item indent: add 1 space'
13011311
]);
13021312

13031313
assertFile('list-item-indent-mixed.md', [

0 commit comments

Comments
 (0)