Skip to content

Commit b25a54e

Browse files
itaisteinherztransitive-bullshit
authored andcommittedApr 29, 2019
Lint sublists in list-item (#77)
* Lint sublists in `list-item` * Improve code structure and tests * Use `unist-util-visit` instead of custom method
1 parent dff8bb7 commit b25a54e

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed
 

‎rules/list-item.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = rule('remark-lint:awesome/list-item', (ast, file) => {
6565
return;
6666
}
6767

68-
lists = findAllAfter(ast, postContentsHeading, {type: 'list'});
68+
lists = extractSublists(findAllAfter(ast, postContentsHeading, {type: 'list'}));
6969
}
7070

7171
for (const list of lists) {
@@ -81,6 +81,16 @@ function findAllLists(ast) {
8181
return lists;
8282
}
8383

84+
function extractSublists(lists) {
85+
let allLists = [];
86+
87+
for (const list of lists) {
88+
allLists = [...allLists, ...findAllLists(list)];
89+
}
90+
91+
return allLists;
92+
}
93+
8494
function validateList(list, file) {
8595
for (const listItem of list.children) {
8696
const [paragraph] = listItem.children;

‎test/fixtures/list-item/3.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Awesome Nest
2+
3+
## Contents
4+
5+
- [Resources](#resources)
6+
7+
## Resources
8+
9+
- Tutorials
10+
- [Nestjs30Days](https://github.com/m24927605/Nestjs30Days) - Learn the Nestjs framework in 30 days
11+
- Unicorns are awesome.
12+
- [foo]() - Invalid url.

‎test/rules/list-item.js

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ test('list-item - invalid', async t => {
1818
t.snapshot(messages);
1919
});
2020

21+
test('list-item - invalid sublist punctuation', async t => {
22+
const messages = await lint({config, filename: 'test/fixtures/list-item/3.md'});
23+
t.snapshot(messages);
24+
});
25+
2126
test('list-item - valid ignoring Contents section', async t => {
2227
const messages = await lint({config, filename: 'test/fixtures/list-item/2.md'});
2328
t.deepEqual(messages, []);

‎test/rules/snapshots/list-item.js.md

+15
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,18 @@ Generated by [AVA](https://ava.li).
6262
ruleId: 'awesome/list-item',
6363
},
6464
]
65+
66+
## list-item - invalid sublist punctuation
67+
68+
> Snapshot 1
69+
70+
[
71+
{
72+
message: 'List item description must end with proper punctuation',
73+
ruleId: 'awesome/list-item',
74+
},
75+
{
76+
message: 'Invalid list item link URL',
77+
ruleId: 'awesome/list-item',
78+
},
79+
]
85 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.