Skip to content

Add check-list-referenced hook to keep README tool commands in sync#1722

Merged
nathanjmcdougall merged 3 commits intomainfrom
copilot/create-hook-system-readme-toc
Apr 1, 2026
Merged

Add check-list-referenced hook to keep README tool commands in sync#1722
nathanjmcdougall merged 3 commits intomainfrom
copilot/create-hook-system-readme-toc

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

After #1639 where an agent failed to update docs when adding a new command, this adds a pre-commit hook that verifies all entries in ALL_TOOL_COMMANDS are referenced in the README. If a developer adds a tool to the registry but forgets to document it, CI catches it.

New hook: hooks/check-list-referenced.py

Generic, reusable hook that:

  • Imports a Python list constant via a dotted module path using importlib (e.g. pkg.mod.VAR_NAME)
  • Checks each string item appears in a target file
  • Contains no project-specific words (passes check-banned-words)

New derived constant: ALL_TOOL_COMMAND_STRS

Added in src/usethis/_ui/interface/tool.py, this constant derives the full prefixed command strings (e.g. "usethis tool ruff") from ALL_TOOL_COMMANDS, so the hook can check them directly without needing a pattern argument.

Registration in .pre-commit-config.yaml

- id: check-list-referenced
  entry: uv run --frozen --offline hooks/check-list-referenced.py
  args:
    - "--variable=usethis._ui.interface.tool.ALL_TOOL_COMMAND_STRS"
    - "--target-file=README.md"

Failure output when a tool is missing from the README:

ERROR: The following items from 'usethis._ui.interface.tool.ALL_TOOL_COMMAND_STRS' are not referenced in README.md:
  - 'usethis tool new-tool'

… in README

Create a generic hook that parses a Python list constant via AST and checks
each item appears in a target file with a given pattern. Register it in
.pre-commit-config.yaml to verify ALL_TOOL_COMMANDS are referenced in README.md.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/99f2cb98-5708-460b-a131-abff18d6a22c

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add hook-based system to keep README TOC up-to-date Add check-list-referenced hook to keep README tool commands in sync Apr 1, 2026
Copilot AI requested a review from nathanjmcdougall April 1, 2026 11:47
Comment thread .pre-commit-config.yaml Outdated
…MMAND_STRS

Replace AST-based source file parsing with importlib-based module import.
The hook now accepts --variable as a dotted path (e.g.
pkg.mod.ALL_TOOL_COMMAND_STRS) and checks each string directly.

Add ALL_TOOL_COMMAND_STRS derived constant in tool.py containing the
prefixed command strings. Remove --source-file and --pattern args.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/38399814-f18a-4a0d-91fd-e52b58a189b6

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 1, 2026 12:09
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 1, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/create-hook-system-readme-toc (aba51fd) with main (b0c8531)

Open in CodSpeed

@nathanjmcdougall nathanjmcdougall merged commit c93a957 into main Apr 1, 2026
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/create-hook-system-readme-toc branch April 1, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a hook-based system to keep the README TOC up-to-date

2 participants