Skip to content

pre-commit hook 'suites' or 'collections' #548

Closed

Description

@dan98765

Disclaimer: An idea for a QoL thing I'm not fully convinced about the usefulness of myself.

Intro: We have several dozen repos that all use pre-commit. It can be a pain to manage the .pre-commit-config.yaml files in each of those repositories separately i.e. we may start or stop using some hooks across all repos and then it takes some effort to update all their .pre-commit-config.yaml files. I and others have various scripts and tools built to do mass updates across repositories, but I was thinking about whether there was a simpler way to maintain and think about this.

Idea: Versioned 'suites' or 'collections' of hooks.
Imagine a repo pre_commit_hook_collections containing some directory collections/:

collections/
  python_package_hooks.yaml
  service_hooks.yaml
  frontend_service_hooks.yaml
  ...

Each of those is a pre-commit config file with the same format as .pre-commit-config.yaml. python_package_hooks.yaml for example might have all the basic hooks we want in every single python package (line ending fixer, pep8, no large files, etc). When we create a new python package we would have it's .pre-commit-config.yaml file look like:

-   repo: [email protected]:pre-commit/pre-commit-hook-collections
    sha: e9446ff0cc8ffa65309e0a37c247518127a3bf18
    collections:
    -   id: python-package-hooks
        language_version: python3.6

pre-commit autoupdate would bump the version of hook collections same as it bumps version of hooks now.

Having a repo's .pre-commit-config.yaml include collection(s) does not mean it can not also specify additional regular precommit hooks. For example, if we add some yaml file to our python package we might specifically add a yaml validator or sorter hook to it.

When we want to add/remove hooks across many repositories it then becomes a job of updating the collections repository with those changes. Then as package authors across the team or multiple teams update their hooks they'll get those changes.

Looking for thoughts on the usefulness of this idea, and feasibility.

Activity

  1. asottile commented on Jun 27, 2017

    @asottile
    Member

    I think a lot of this will be addressed with configuration v2: #414

    I'm also hesitant:

    • this will be pretty complicated to implement
    • it'll make it nearly impossible to answer "where is this hook being included from"
    • I probably won't use this feature
    • It will be difficult / impossible to maintain open source collections as downstreams will generally not expect / want them to change (every change / addition / removal will essentially be breaking)
    • it's now two upgrades to get the latest -- first an update in the collections repository and then a bump in the consuming repository.
  2. asottile commented on Jul 3, 2017

    @asottile
    Member

    This would also make it impossible to add exclude / language_version / etc. (or other configuration) to individual hooks. I don't think this is possible so I'm going to close this. @dlgallagher feel free to reopen if you have additional ideas :)

  3. dan98765 commented on Jul 3, 2017

    @dan98765
    Author

    @asottile thanks for your thoughts on this idea! I'm not familiar with the pre-commit code so I don't have any idea how hard it would be to implement this. If I end up getting inspired sometime down the line to try building this feature I'll try testing it out for awhile to see what all the issues are. Until then it's not that high on my priority list & no need to discuss further here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions