Hook to check stale file references - #174
Conversation
| alternatives: list[str] = [] | ||
| for i in range(len(segments)): | ||
| suffix = "/".join(segments[i:]) | ||
| escaped_suffix = re.escape(suffix) |
There was a problem hiding this comment.
Do we have a test that checks the need for this?
There was a problem hiding this comment.
The # noqa: S607 suppresses a ruff lint rule (partial executable path), not a runtime behavior — there's no test that would exercise it. It's now consolidated into the single _run_git() helper so there's only one suppression.
There was a problem hiding this comment.
I mean the re.escape part. Do we have a test for that?
There was a problem hiding this comment.
Good point — added test_dot_in_extension_is_literal which asserts that fooXhpp does not match foo.hpp (without re.escape, the . would match any character).
There was a problem hiding this comment.
Pull request overview
Adds a new check-stale-references pre-commit hook intended to detect references to deleted/renamed files (by full repo-relative path and by basename) in the remaining tracked files, helping prevent broken cross-references after refactors.
Changes:
- Introduces
dev_tools.check_stale_referencesimplementation and a console entrypoint (check-stale-references). - Adds test coverage for pattern-building, detection, and output formatting.
- Wires the hook into
.pre-commit-hooks.yamland documents it inREADME.md.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
dev_tools/check_stale_references.py |
Implements stale-reference detection and printing for use as a pre-commit hook. |
tests/test_check_stale_references.py |
Adds unit tests for matching behavior and reporting. |
pyproject.toml |
Registers the new console script and adjusts Ruff test ignores. |
.pre-commit-hooks.yaml |
Adds the new check-stale-references hook definition. |
README.md |
Documents the new hook in the Tools section and TOC. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…oundaries - Replace Python file I/O with git grep for performance - Extract _run_git() helper using subprocess.run(check=True) - Simplify D/R branch in get_deleted_paths (both use parts[1]) - Add __str__ to StaleReference, remove print_stale_references - Tighten regex boundaries to [\w.-] to reject foo.hpp.bak etc. - Remove unused get_repo_root and get_tracked_files
Closes #162