Skip to content

Add glob list support for file patterns (files and exclude)#1197

Merged
j178 merged 10 commits intoj178:masterfrom
Goldziher:master
Jan 16, 2026
Merged

Add glob list support for file patterns (files and exclude)#1197
j178 merged 10 commits intoj178:masterfrom
Goldziher:master

Conversation

@Goldziher
Copy link
Contributor

@Goldziher Goldziher commented Dec 6, 2025

This PR adds support for glob patterns:

# Top-level defaults
  files:
    glob:
      - src/**/*.rs
      - crates/**/src/**/*.rs
  exclude:
    glob:
      - target/**
      - dist/**

  repos:
    - repo: local
      hooks:
        - id: fmt-rust
          entry: cargo fmt --all
          language: system
          # Single glob is fine too:
          files:
            glob: src/**/*.rs
          # Regex still works as before (default form
  without `glob:`):
          exclude: (^|/)vendor/.*

        - id: lint-js
          entry: pnpm lint
          language: system
          files:
            glob:
              - web/src/**/*.ts
              - web/src/**/*.tsx
          exclude:
            glob: web/src/**/__tests__/**

Why? The new monorepo support prek offers is nice, but its limited. In glob patterns enhance this further making prek much more versatile - globs are one of the key features of lefthook, that are missing. Furthermore, the pattern usage from pre-commit is inefficient and not very nice to work with - in my humble opinion, so this PR offers a completely backwards compatible alternative. Default is what it always was, while you can opt in to glob patterns.

@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 96.17021% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.29%. Comparing base (be8f49e) to head (275427e).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/hooks/meta_hooks.rs 88.67% 6 Missing ⚠️
crates/prek/src/config.rs 97.81% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1197      +/-   ##
==========================================
+ Coverage   90.25%   90.29%   +0.03%     
==========================================
  Files          81       81              
  Lines       15952    16116     +164     
==========================================
+ Hits        14398    14552     +154     
- Misses       1554     1564      +10     

☔ 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.

@github-actions
Copy link

github-actions bot commented Dec 6, 2025

📦 Cargo Bloat Comparison

Binary size change: +0.90% (22.3 MiB → 22.5 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 72.4KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 54.7KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 49.9KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 47.0KiB         prek prek::run::{{closure}}
 0.2%   0.5% 43.0KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 35.0KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.8KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 29.2KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.3% 27.6KiB         prek prek::identify::by_extension::{{closure}}
 0.1%   0.2% 21.5KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB 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% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.2KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.8KiB         prek prek::main
36.6%  91.8%  8.2MiB              And 19859 smaller methods. Use -n N to show more.
39.8% 100.0%  9.0MiB              .text section size, the file size is 22.5MiB

Base Branch Results

 File  .text    Size        Crate Name
 0.3%   0.8% 72.3KiB        prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.2%   0.6% 54.7KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 49.9KiB         prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 46.8KiB         prek prek::run::{{closure}}
 0.2%   0.5% 42.4KiB         prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 35.0KiB         prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.1%   0.3% 31.9KiB        prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 29.2KiB  serde_json? <&mut serde_json::de::Deserializer<R> as serde_core::de::Deserializer>::deserialize_struct
 0.1%   0.3% 27.6KiB         prek prek::identify::by_extension::{{closure}}
 0.1%   0.2% 21.6KiB         prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 21.3KiB clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.3KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 20.1KiB         prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.6KiB         prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 19.2KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.9KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 18.6KiB         ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.2KiB   hyper_util hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
 0.1%   0.2% 18.1KiB    [Unknown] fe_loose_invert
 0.1%   0.2% 17.7KiB         prek prek::cli::run::filter::collect_files_from_args::{{closure}}
36.6%  91.8%  8.2MiB              And 19623 smaller methods. Use -n N to show more.
39.9% 100.0%  8.9MiB              .text section size, the file size is 22.3MiB

@Goldziher
Copy link
Contributor Author

@j178 - hi. Can you enable running github actions for users who are not new to github? its an optional setting. It will make contributing here much simpler.

@j178 j178 added enhancement New feature or request thinking I'm thinking on this labels Dec 7, 2025
@j178
Copy link
Owner

j178 commented Dec 8, 2025

Thanks for contributing — this looks good! But since this is a new feature, I’ll need a bit more time to think through the interface design and the overall user experience.

Also, dependencies are normally updated by the Renovate bot, so we usually don’t include them in feature PRs. It doesn’t look like they’re needed for this one, right?

@Goldziher
Copy link
Contributor Author

Thanks for contributing — this looks good! But since this is a new feature, I’ll need a bit more time to think through the interface design and the overall user experience.

Also, dependencies are normally updated by the Renovate bot, so we usually don’t include them in feature PRs. It doesn’t look like they’re needed for this one, right?

yup not needed. I just ran cargo update, will undo and rebase.

@Goldziher
Copy link
Contributor Author

@j178 - rebased on main and removed the Cargo.toml/lock version updates. Lemme know if you need me to rebase again in the future.

@j178 j178 changed the title feat: add glob list support for file patterns Add glob list support for file patterns Jan 16, 2026
@j178 j178 removed the thinking I'm thinking on this label Jan 16, 2026
@j178 j178 requested a review from Copilot January 16, 2026 08:34
@j178 j178 changed the title Add glob list support for file patterns Add glob list support for file patterns (files and exclude) Jan 16, 2026
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 adds support for glob patterns as an alternative to regex patterns for the files and exclude fields in prek configuration. The change maintains full backward compatibility with existing regex-based configurations.

Changes:

  • Introduced FilePattern enum supporting both regex (default) and glob patterns (single or list)
  • Updated all file/exclude pattern references throughout the codebase to use the new type
  • Added comprehensive test coverage for glob pattern matching and edge cases

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/prek/src/config.rs Core implementation of FilePattern enum with deserialization, matching, and display logic
crates/prek/src/hook.rs Updated Hook struct to use FilePattern instead of SerdeRegex
crates/prek/src/cli/run/filter.rs Updated FilenameFilter to work with FilePattern type
crates/prek/src/hooks/meta_hooks.rs Updated meta hooks to use FilePattern and improved error messages
prek.schema.json JSON schema definition for the new FilePattern type supporting regex and glob variants
docs/configuration.md Documentation explaining glob pattern usage with examples
crates/prek/tests/run.rs Integration test demonstrating glob patterns with multiple hooks
crates/prek/tests/meta_hooks.rs Updated snapshot tests reflecting new error message format
crates/prek/src/snapshots/*.snap Updated snapshots showing Regex() wrapper and improved formatting
Cargo.toml Added globset dependency
crates/prek/src/cli/auto_update.rs Added GPG signing disablement for test commits (unrelated fix)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@j178 j178 merged commit 392eb2d into j178:master Jan 16, 2026
19 checks passed
@j178
Copy link
Owner

j178 commented Jan 16, 2026

Thank you, let's merge!

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.

3 participants