-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathno-todo.js
52 lines (50 loc) · 1.4 KB
/
no-todo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// LICENSE : MIT
"use strict";
import {RuleHelper} from "textlint-rule-helper";
/**
* @param {RuleContext} context
*/
export default function (context) {
const helper = new RuleHelper(context);
const {Syntax, getSource, RuleError, report} = context;
return {
/*
Match pattern
# Header
TODO: quick fix this.
^^^^^
Hit!
*/
[Syntax.Str](node) {
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote])) {
return;
}
// get text from node
const text = getSource(node);
// does text contain "todo:"?
const match = text.match(/todo:/i);
if (match) {
const todoText = text.substring(match.index);
report(node, new RuleError(`Found TODO: '${todoText}'`, {
index: match.index
}));
}
},
/*
Match Pattern
# Header
- [ ] Todo
^^^
Hit!
*/
[Syntax.ListItem](node) {
const text = context.getSource(node);
const match = text.match(/\[\s+\]\s/i);
if (match) {
report(node, new context.RuleError(`Found TODO: '${text}'`, {
index: match.index
}));
}
}
};
}