Skip to content

Commit 5eb75b1

Browse files
Update prek skills to warn against directory-scoped files patterns (#1839)
* Initial plan * Update prek skills to warn against directory-scoped files patterns Update usethis-prek-hook-bespoke-create (v1.2 → v1.3) and usethis-prek-add-hook (v1.4 → v1.5) to explicitly warn against using directory-scoped `files` patterns when configuring prek hooks. Resolves #1838 Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/82e3d1c4-6873-4c27-8d11-a07195120215 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent 31a0d16 commit 5eb75b1

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

  • .agents/skills

.agents/skills/usethis-prek-add-hook/SKILL.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Add a prek hook for dev
44
compatibility: usethis, prek, git
55
license: MIT
66
metadata:
7-
version: "1.4"
7+
version: "1.5"
88
---
99

1010
# Adding a prek Hook
@@ -60,6 +60,17 @@ repos:
6060
priority: 1
6161
```
6262

63+
## File targeting: avoid directory-scoped `files` patterns
64+
65+
Never use `files` to restrict hooks to specific directories (e.g. `files: ^(src|tests)/`). Directory-scoped hooks silently miss violations in unexpected locations and create a false sense of coverage. If a check is worth running, it is worth running everywhere.
66+
67+
Instead, use one of these approaches:
68+
69+
- **`types: [python]`** (or other type filters) to match all files of a given type across the entire repository.
70+
- **`pass_filenames: false`** with `always_run: true`, letting the hook script determine its own file targets via CLI arguments.
71+
72+
The narrow exception is `pygrep`-language hooks where the matched pattern is only a violation in a specific directory — for example, a pattern that flags test-only anti-patterns which are perfectly valid in production code. In such cases, `files` scoping prevents false positives rather than hiding true violations. Even then, combine `files` with `types` filters to keep the scope as tight as possible.
73+
6374
## Setting the `priority` field
6475

6576
Every hook **must** have an explicit `priority` field. prek uses `priority` to enable concurrent execution of hooks — hooks at the same priority level run in parallel, while different priority levels run sequentially (lower numbers first). See the [prek priority documentation](https://prek.j178.dev/configuration/#priority) for more details.

.agents/skills/usethis-prek-hook-bespoke-create/SKILL.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Write bespoke prek hooks as reusable Python scripts for custom chec
44
compatibility: usethis, prek, git, Python
55
license: MIT
66
metadata:
7-
version: "1.2"
7+
version: "1.3"
88
---
99

1010
# Bespoke Prek Hooks
@@ -123,5 +123,12 @@ Key points:
123123
- `id` and `name` should match the script filename (without `.py`).
124124
- Set `pass_filenames: false` since bespoke hooks typically determine their own
125125
file targets.
126+
- **Never use `files` to scope hooks to specific directories** (e.g.
127+
`files: ^(src|tests)/`). Directory-scoped hooks silently miss violations in
128+
unexpected locations and create a false sense of coverage. Instead, use
129+
`types: [python]` (or other type filters) to match files by type across the
130+
entire repository, or use `pass_filenames: false` and let the hook script
131+
determine its own file targets via CLI arguments. If a check is worth running,
132+
it is worth running everywhere.
126133
- Follow the `usethis-prek-add-hook` skill for priority assignment and placement
127134
within the file.

0 commit comments

Comments
 (0)