From e708a1c802a849b4da3809d24a24d53e3e648a58 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 15 Jan 2016 11:19:28 +0100 Subject: [PATCH] Fix `list-item-indent` for non-incremented lists Closes GH-40. --- lib/rules/list-item-indent.js | 11 ++++++----- test/fixtures/list-item-indent-space.md | 13 +++++++++++++ test/index.js | 12 +++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/rules/list-item-indent.js b/lib/rules/list-item-indent.js index 2350c6f0..14651223 100644 --- a/lib/rules/list-item-indent.js +++ b/lib/rules/list-item-indent.js @@ -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; @@ -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') { diff --git a/test/fixtures/list-item-indent-space.md b/test/fixtures/list-item-indent-space.md index 099c4a98..4d882faf 100644 --- a/test/fixtures/list-item-indent-space.md +++ b/test/fixtures/list-item-indent-space.md @@ -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 diff --git a/test/index.js b/test/index.js index a3af5c05..9ae2f42e 100644 --- a/test/index.js +++ b/test/index.js @@ -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', [