lofidevops
lofidevops

Reputation: 16982

Can I configure universal pre-commit hooks for my machine?

I am interested in adopting the pre-commit framework. I would like to create hooks for common errors that I tend make. For example, I want to:

These hooks are likely not appropriate for inclusion in project-specific repos, so they should not be stored in $PROJECT/.pre-commit-config.yaml. Additionally, I don't want to have to copy them into every single repo I clone.

Is there a local location (in $XDG_CONFIG_HOME maybe?) for a "universal" .pre-commit-config.yaml?

(Ideally the solution should be compatible with projects that do define their own pre-commit config.)

Upvotes: 1

Views: 780

Answers (1)

anthony sottile
anthony sottile

Reputation: 69964

not sure why "not committing to master / main" wouldn't be appropriate in the repo config though -- it's one of the more popular out of the box hooks

there is intentionally not a supported path for what you want -- the intent of pre-commit is that the exact linting tools are versioned along with the repository so everything is kept consistent for all contributors

that said, you can add a legacy hook which calls pre-commit with your custom hooks

#!/usr/bin/env bash
exec pre-commit run --config ~/.config/pre-commit/config.yaml`

put that at .git/hooks/pre-commit.legacy (or make it part of your init.templateDir similar to what's written about here)


disclaimer: I wrote pre-commit

Upvotes: 1

Related Questions