Skip to content

Enable filtering files based on pattern when using prek manually#729

Description

@martis42

First of all, thank you very much for starting this project 馃挌

I really liked that you introduced the --directory option. I was missing this always in pre-commit.

It would be an awesome addition, if we could also get a --file-filters (or whatever name suits you) option allowing us to provide patterns and prek will then only check files matching the patterns.

Example use cases I think of are

  • I want to check all .foo files in the workspace
  • I want to test all files below ../test/.. directories

I know one can achieve this by using --files and combining this with git ls-files. However, I believe this is needlessly clunky for something which I consider a standard use case.

Assuming you are open for the request at all, I see the following design decisions for this new option:

  • Does this new option have to be used mutually exclusive with respect to --all-files and --directory? Or is it allowed to use --all-files or --directory and then on top apply further file filters.
  • Should the option expect glob or regex patterns

No strong opinion on those. Although, If I could freely choose, I guess being able to combine --directoy with filters would be nice as this would allow simpler patterns in some cases. Also regex seems like the most powerful choice for writing file patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions