Skip to content

Allow pass_filenames to accept a positive integer#1698

Merged
j178 merged 2 commits intoj178:masterfrom
JP-Ellis:feat/allow-pass-filenames-int
Feb 28, 2026
Merged

Allow pass_filenames to accept a positive integer#1698
j178 merged 2 commits intoj178:masterfrom
JP-Ellis:feat/allow-pass-filenames-int

Conversation

@JP-Ellis
Copy link
Contributor

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: #1471

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]>
Copilot AI review requested due to automatic review settings February 27, 2026 10:07
@JP-Ellis JP-Ellis requested a review from j178 as a code owner February 27, 2026 10:07
@JP-Ellis JP-Ellis force-pushed the feat/allow-pass-filenames-int branch from 3be02a8 to 1171596 Compare February 27, 2026 10:07
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 96.70330% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.57%. Comparing base (f7b0c00) to head (e976fae).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/config.rs 97.22% 2 Missing ⚠️
crates/prek/src/run.rs 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PassFilenames enum to support boolean values and positive integers
  • Updated batching logic to respect the per-invocation file limit
  • Extended JSON schema to allow pass_filenames as 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

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 27, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (23.9 MiB → 23.9 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.4KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 70.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.5KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.8KiB              prek prek::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 24.7KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.8KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.7KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 22.5KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.8KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.2KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 19.4KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.2KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 18.7KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
 0.1%   0.2% 18.6KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
38.3%  91.8%  9.2MiB                   And 21075 smaller methods. Use -n N to show more.
41.8% 100.0% 10.0MiB                   .text section size, the file size is 23.9MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 80.2KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.4KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 38.8KiB              prek prek::run::{{closure}}
 0.1%   0.3% 31.1KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.5KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 24.7KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.8KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.7KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 22.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.1KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.5KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.2KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.5KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 18.7KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
 0.1%   0.2% 18.6KiB     serde_saphyr? <serde_saphyr::de::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map
38.3%  91.7%  9.1MiB                   And 21096 smaller methods. Use -n N to show more.
41.7% 100.0% 10.0MiB                   .text section size, the file size is 23.9MiB

@JP-Ellis
Copy link
Contributor Author

Glad to see all of CI is passing. In terms of the code coverage, there are a few branches of the Deserialize implementation which are missing. Let me know if you need me to implement tests to cover these, or whether the existing unit tests will suffice.

@j178 j178 added the enhancement New feature or request label Feb 27, 2026
@j178 j178 requested a review from Copilot February 27, 2026 10:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

@j178
Copy link
Owner

j178 commented Feb 27, 2026

Let me know if you need me to implement tests to cover these

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]>
Copilot AI review requested due to automatic review settings February 27, 2026 21:15
@JP-Ellis JP-Ellis force-pushed the feat/allow-pass-filenames-int branch from 201973a to e976fae Compare February 27, 2026 21:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment on lines +1086 to +1088
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`.
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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`.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JP-Ellis
Copy link
Contributor Author

Done! Test coverage of now much higher 🙂

@j178 j178 merged commit ce3ecf3 into j178:master Feb 28, 2026
52 of 53 checks passed
@j178
Copy link
Owner

j178 commented Feb 28, 2026

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add setting to force one tool invocation per affected file

3 participants