Skip to content

agent: never scope prek hooks to specific directories — use types or pass_filenames instead #1838

@nathanjmcdougall

Description

@nathanjmcdougall

What happened

The check-comment-keywords prek hook was configured with files: ^(src|tests)/, restricting it to only source and test directories. This was caught in code review.

Root cause

The hook was configured based on the literal wording of the issue description ("scanning all Python files in src/ and tests/") rather than following the established conventions of existing hooks in the project. Existing hooks like check-docstring-substrings use types: [python] without any files restriction, applying to all Python files in the repository.

Generalised principle

When configuring prek hooks, never scope them to specific directories (e.g. files: ^(src|tests)/). Instead, either:

  1. Use types: [python] (or other type filters) to match all files of a given type across the entire repository, or
  2. Use pass_filenames: false and let the hook script determine its own file targets via CLI arguments.

Directory-scoped hooks are fragile — they silently miss violations in unexpected locations and create a false sense of coverage. If a check is worth running, it is worth running everywhere.

Resolution

Removed the files: ^(src|tests)/ line from the check-comment-keywords hook entry in .pre-commit-config.yaml, leaving types: [python] as the sole file filter.

Follow-up

Consider updating the usethis-prek-hook-bespoke-create and usethis-prek-add-hook skills to explicitly warn against directory-scoped files patterns for hooks that should apply project-wide.

Metadata

Metadata

Labels

agentConfiguration updates for LLM coding agents

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions