Skip to content

Commit 121b462

Browse files
committed
Add script, add script to ci.yml
1 parent 1e8d164 commit 121b462

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,15 @@ jobs:
226226

227227
- name: Check for unused dependencies
228228
run: cargo udeps --all --all-features
229+
check-todos:
230+
name: Check TODOs
231+
runs-on: ubuntu-latest
232+
steps:
233+
- name: Checkout Actions Repository
234+
uses: actions/checkout@v3
235+
236+
- name: Setup Python
237+
uses: actions/setup-python@v5
238+
239+
- name: Run todo checker script
240+
run: python scripts/check_todos.py

scripts/check_todos.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pathlib
2+
import re
3+
4+
5+
def check(lines: list[str]) -> list[tuple[int, str]]:
6+
results = []
7+
for (i, line) in enumerate(lines):
8+
result = re.search(r"((//|/\*|///).*TODO|todo!)(?!.*\(#\d+\))", line)
9+
if result:
10+
results.append((i, line))
11+
return results
12+
13+
if __name__ == "__main__":
14+
paths = list(pathlib.Path(".").rglob("*"))
15+
16+
clean = True
17+
for path in paths:
18+
if path.is_file():
19+
with open(path, "r") as f:
20+
try:
21+
lines = f.readlines()
22+
for (i, line) in check(lines):
23+
if clean:
24+
clean = False
25+
print(f"[{path}:{i}] {line}", end="")
26+
except UnicodeDecodeError:
27+
continue
28+
29+
if not clean:
30+
print("\nYour code has TODOs that don't reference any issues! Create issues for your todos and reference them like this: `(#<issue number>)`. Example: // TODO: Foo (#123)")
31+
exit(1)

0 commit comments

Comments
 (0)