Make consistent good commits with pre-commit

This project makes use of git hooks to ensure commited content adheres to current common practices and current style guidelines.


What is pre-commit?

In a nutshell: pre-commit makes git hooks more usable across repositories where more than one person is working on. It easy to install and offers a simple yet thoroughly extensible configuration file.

pre-commit hooks are an easy way to verify changes locally prior to commiting them. This helps to reduce the number of commits as all pre-commit hooks are enforced through continous integration (CI) pipelines in GitHub.


Table of contents

Hooks in use

pre-commit allows to reference hooks from other repositories. Some repositories of tools used in this repository (e.g. renovate or yamllint provide a hook configuration (defined in .pre-commit-hooks.yaml) out of the box, while some tools do not. For such cases, individuals can step up and create a repository solely for the purpose of serving a .pre-commit-hooks.yaml configuration, which enables users of pre-commit to share their hook configuration.

Within the next few sections all repositories utilized by this project are listed and their purpose for this project described.

In each section, you’ll find the pre-commit hook IDs that are utilized of the respective repository and in which stages.

Repository https://github.com/ansible/ansible-lint

Hook IDspre-commit stages
ansible-lintpre-commit

This hook is used to validate Ansible YAML code using Ansible Lint. The configuration this hook uses is stored in .ansible-lint in the root of the repository.

Under the hood Ansible Lint calls yamllint to verify YAML files. This means that the configuration for yamllint, which is stored in the root of the repository in .yamllint, is also applied by Ansible Lint for Ansible-specific files.

Ansible Lint needs to check all Ansible related files, not just the ones that changed, as it otherwise leads to false-positives. This, however, means that Ansible Lint will take much more time - especially the more Ansible related files are in the repository - as it needs to check all Ansible-related files on every commit.

Repository https://github.com/pre-commit/pre-commit-hooks

Hook IDspre-commit stages
check-executables-have-shebangspre-commit
check-merge-commitpre-commit
check-jsonpre-commit
check-shebang-scripts-are-executablespre-commit
check-symlinkspre-commit
check-tomlpre-commit
check-xmlpre-commit
debug-statementspre-commit
destroyed-symlinkspre-commit
detect-private-keypre-commit
end-of-file-fixerpre-commit
mixed-line-endingpre-commit
pretty-format-jsonpre-commit
trailing-whitespacepre-commit

These hooks are officially from the pre-commit community and they contain all sorts of useful checks.

Each of them is described and documented in the repository they are pulled from.