To facilitate starting a new project, I started to gather all the pre-commit yaml that the project will use
Git hook scripts are useful for identifying simple issues before submission to code review. We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements. By pointing these issues out before code review, this allows a code reviewer to focus on the architecture of a change while not wasting time with trivial style nitpicks.
TL;DR: when developing collaboratively, we typically use git for version control and commit any changes to a feature branch that is reviewed before merging into the main codebase.
The problem is - nothing stops us from committing low-quality code to the git repository.
So to improve our code quality and unify the layout, styles etc, pre-commit
hook is here to help
-
Using pip:
$ pip install pre-commit
-
MacOS: homebrew
brew install pre-commit
-
Conda:
conda install -c conda-forge pre-commit
You can simple copy paste one of the example in the collection folders, or run
$ pre-commit sample-config
to generate a basic config.
Then you will need to install it
$ pre-commit install
To verify the commit message, you will need to also install
$ pre-commit install --hook-type commit-msg
For morte configureation, please check https://pre-commit.com/#pre-commit-configyaml---top-level
To use it in CI: https://pre-commit.com/#usage-in-continuous-integration
Also, in some ci/cd services, there's already some "stage" avaiable