forked from software-mansion/starknet.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylint_todo_checker.py
34 lines (27 loc) · 1.02 KB
/
pylint_todo_checker.py
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
import re
import tokenize
from pylint import checkers, interfaces
def register(linter: "PyLinter") -> None:
"""
This required method auto registers the checker during initialization.
:param linter: The linter to register the checker to.
"""
linter.register_checker(TodoTokenChecker(linter))
class TodoTokenChecker(checkers.BaseTokenChecker):
name = "todo-issue-error"
priority = -1
msgs = {
"E2137": (
"Invalid TODO format, should be: '# TODO (#issue number): ...'.",
name,
"TODO comments should be in a format: '# TODO (#issue number): ...'.",
),
}
def process_tokens(self, tokens):
for token in tokens:
if token.type == tokenize.COMMENT:
quotes_stripped = token.string.strip('"').strip("'")
if "TODO" in quotes_stripped and not re.match(
"#\s*TODO\s*\(#\d+\):.*", quotes_stripped
):
self.add_message(self.name, line=token.start[0])