Allow pass_filenames to accept a positive integer#1698
Conversation
Setting `pass_filenames: n` limits each hook invocation to at most `n` filenames, with multiple parallel invocations for larger file sets. This mirrors the `-n` flag of `xargs` and is useful for tools that can only process a limited number of files per invocation (typically, if a limit applies, it is 1). The existing boolean behaviour is preserved: `true` passes all filenames (default) and `false` passes none. So this is a backwards compatible change. Resolves: j178#1471 Signed-off-by: JP-Ellis <[email protected]>
3be02a8 to
1171596
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1698 +/- ##
========================================
Coverage 91.57% 91.57%
========================================
Files 96 96
Lines 18842 18976 +134
========================================
+ Hits 17255 17378 +123
- Misses 1587 1598 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends the pass_filenames configuration option to accept positive integers in addition to booleans, enabling fine-grained control over how many files are passed to each hook invocation. This addresses issue #1471 where tools like comrak can only process one file at a time.
Changes:
- Added
PassFilenamesenum to support boolean values and positive integers - Updated batching logic to respect the per-invocation file limit
- Extended JSON schema to allow
pass_filenamesas boolean or positive integer
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/prek/src/config.rs |
Added PassFilenames enum with custom deserializer supporting bool and positive integer values |
crates/prek/src/schema.rs |
Added JSON schema implementation for PassFilenames type |
crates/prek/src/run.rs |
Updated batching logic to use PassFilenames::Limited(n) for batch size calculation |
crates/prek/src/cli/run/run.rs |
Updated filename filtering to match on enum variants instead of boolean |
crates/prek/src/hook.rs |
Changed pass_filenames field type from bool to PassFilenames |
crates/prek/src/hooks/builtin_hooks/mod.rs |
Updated builtin hook to use PassFilenames::None instead of false |
prek.schema.json |
Updated schema to reference PassFilenames definition instead of boolean type |
docs/configuration.md |
Added documentation for the new integer option with clear examples |
crates/prek/tests/run.rs |
Added integration test verifying one-file-at-a-time behavior |
crates/prek/src/snapshots/*.snap |
Updated snapshots to reflect enum representation |
📦 Cargo Bloat ComparisonBinary size change: +0.00% (23.9 MiB → 23.9 MiB) Expand for cargo-bloat outputHead Branch ResultsBase Branch Results |
|
Glad to see all of CI is passing. In terms of the code coverage, there are a few branches of the |
That would be great, Thanks! |
In particular, this adds: - A test for passing at most 2 files - Negative tests, checking the validation of strings and invalid integer values. Signed-off-by: JP-Ellis <[email protected]>
201973a to
e976fae
Compare
| Set `pass_filenames: n` (a positive integer) to limit each invocation to at most `n` filenames. When there are more matching files than `n`, `prek` spawns multiple invocations and runs them in parallel. This is useful for tools that can only process a limited number of files at once. | ||
|
|
||
| Prek will automatically limit the number of filenames to ensure command lines don’t exceed the OS limit, even when `pass_filenames: true`. |
There was a problem hiding this comment.
This text says prek “runs them in parallel”, but actual parallelism is conditional (e.g., require_serial: true or PREK_NO_CONCURRENCY forces concurrency=1). Consider qualifying this as “may run them in parallel” (up to prek’s concurrency limits) to avoid implying parallelism is guaranteed. Also, “Prek” here is inconsistent with the earlier prek branding in this section.
| Set `pass_filenames: n` (a positive integer) to limit each invocation to at most `n` filenames. When there are more matching files than `n`, `prek` spawns multiple invocations and runs them in parallel. This is useful for tools that can only process a limited number of files at once. | |
| Prek will automatically limit the number of filenames to ensure command lines don’t exceed the OS limit, even when `pass_filenames: true`. | |
| Set `pass_filenames: n` (a positive integer) to limit each invocation to at most `n` filenames. When there are more matching files than `n`, `prek` spawns multiple invocations and may run them in parallel (up to `prek`’s concurrency limits). This is useful for tools that can only process a limited number of files at once. | |
| `prek` will automatically limit the number of filenames to ensure command lines don’t exceed the OS limit, even when `pass_filenames: true`. |
There was a problem hiding this comment.
I would say that since parallel is on by default, this comment is valid. The alternative could be to not mention parallelism at all, as it is determined by other parameters. @j178, let me know if you have a preference.
|
Done! Test coverage of now much higher 🙂 |
|
Thank you! |
Setting
pass_filenames: nlimits each hook invocation to at mostnfilenames, with multiple parallel invocations for larger file sets. This mirrors the-nflag ofxargsand is useful for tools that can only process a limited number of files per invocation (typically, if a limit applies, it is 1).The existing boolean behaviour is preserved:
truepasses all filenames (default) andfalsepasses none. So this is a backwards compatible change.Resolves: #1471