Created
March 9, 2026 11:41
-
-
Save tilacog/612c0418e54bd63bf53c6491643912da to your computer and use it in GitHub Desktop.
Scans a Rust project directory and assigns unique sequential numbers to any un-numbered `// TODO` comments in-place (e.g. `// TODO` → `// TODO(42)`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """Number unnumbered // TODO comments across Rust files.""" | |
| import re | |
| import sys | |
| from pathlib import Path | |
| # Matches "// TODO" NOT followed by "(number)" | |
| UNNUMBERED_TODO = re.compile(r"// TODO(?!\(\d+\))") | |
| def find_rust_files(directory: Path): | |
| return sorted(directory.rglob("*.rs")) | |
| def number_todos(directory: Path): | |
| rust_files = find_rust_files(directory) | |
| counter = 0 | |
| for path in rust_files: | |
| text = path.read_text() | |
| new_lines = [] | |
| changed = False | |
| for line in text.splitlines(keepends=True): | |
| if UNNUMBERED_TODO.search(line): | |
| counter += 1 | |
| line = UNNUMBERED_TODO.sub(f"// TODO({counter})", line, count=1) | |
| changed = True | |
| new_lines.append(line) | |
| if changed: | |
| path.write_text("".join(new_lines)) | |
| print(f"Updated: {path}") | |
| print(f"\nNumbered {counter} TODO(s) across {len(rust_files)} file(s).") | |
| if __name__ == "__main__": | |
| target = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(".") | |
| if not target.is_dir(): | |
| print(f"Error: {target} is not a directory", file=sys.stderr) | |
| sys.exit(1) | |
| number_todos(target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment