Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,15 @@ jobs:

- name: Check for unused dependencies
run: cargo udeps --all --all-features
check-todos:
name: Check TODOs
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v5

- name: Run todo checker script
run: python scripts/check_todos.py .github assets benches crates examples extractor/src scripts src tools website
34 changes: 34 additions & 0 deletions scripts/check_todos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pathlib
import re
import sys


def check(lines: list[str]) -> list[tuple[int, str]]:
results = []
for (i, line) in enumerate(lines):
result = re.search(r"((//|/\*|///|#).*TODO|todo!)(?!.*\(#\d+\))", line)
if result:
results.append((i, line))
return results

if __name__ == "__main__":
paths = []
for directory in sys.argv[1:]:
paths.extend(pathlib.Path(directory).rglob("*"))

clean = True
for path in paths:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Do you think it would be better to have a whitelist or blacklist for scanning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit 5c8a13d I made it so that the script only searches these directories: .github assets benches crates examples extractor/src scripts src tools website. Is this good enough?

if path.is_file():
with open(path, "r") as f:
try:
lines = f.readlines()
for (i, line) in check(lines):
if clean:
clean = False
print(f"[{path}:{i}] {line}", end="")
except UnicodeDecodeError:
continue

if not clean:
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)")
exit(1)