Skip to content

Commit

Permalink
Fix list-item-indent for non-incremented lists
Browse files Browse the repository at this point in the history
Closes GH-40.
  • Loading branch information
wooorm committed Jan 15, 2016
1 parent a95b422 commit e708a1c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/rules/list-item-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,17 @@ function listItemIndent(ast, file, preferred, done) {

visit(ast, 'list', function (node) {
var items = node.children;
var isOrdered = node.ordered;
var offset = node.start || 1;

if (position.generated(node)) {
return;
}

items.forEach(function (item, index) {
items.forEach(function (item) {
var head = item.children[0];
var bulletSize = isOrdered ? String(offset + index).length + 1 : 1;
var tab = Math.ceil(bulletSize / 4) * 4;
var initial = start(item).offset;
var final = start(head).offset;
var bulletSize;
var tab;
var marker;
var shouldBe;
var diff;
Expand All @@ -119,6 +117,9 @@ function listItemIndent(ast, file, preferred, done) {

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

bulletSize = marker.trimRight().length;
tab = Math.ceil(bulletSize / 4) * 4;

if (preferred === 'tab-size') {
shouldBe = tab;
} else if (preferred === 'space') {
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/list-item-indent-space.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ And an extra test for numbers:

11. baz
3

And many items:

1. One
1. Two
1. Three
1. Four
1. Five
1. Six
1. Seven
1. Eight
1. Nine
1. Ten
12 changes: 11 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,17 @@ describe('Rules', function () {
'list-item-indent-space.md:29:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:32:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:37:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:43:4: Incorrect list-item indent: add 1 space'
'list-item-indent-space.md:43:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:54:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:55:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:56:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:57:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:58:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:59:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:60:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:61:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:62:4: Incorrect list-item indent: add 1 space',
'list-item-indent-space.md:63:4: Incorrect list-item indent: add 1 space'
]);

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

0 comments on commit e708a1c

Please sign in to comment.