pre-commit-hooks
pre-commit-hooks provides a collection of frequently used Git hooks for the `pre-commit` framework, facilitating code quality checks such as trailing whitespace, end-of-file fixers, JSON/YAML validation, and detection of large files. Currently at version 6.0.0, the library releases updates periodically, often alongside the `pre-commit` framework itself, to introduce new hooks, fix issues, or update Python version requirements.
Warnings
- breaking Version 6.0.0 of pre-commit-hooks requires Python 3.9 or newer. Ensure your environment meets this requirement when upgrading.
- breaking The hooks `check-byte-order-marker` and `fix-encoding-pragma` were removed in v6.0.0. `fix-encoding-pragma` was deprecated in v4.6.0.
- breaking The `file-contents-sorter` hook in v6.0.0 disallows the simultaneous use of `--unique` and `--ignore-case` arguments.
- deprecated The `check-docstring-first` hook is fundamentally flawed and has been deprecated without a direct replacement.
- gotcha This library is a collection of hooks for the `pre-commit` framework. It must be configured via a `.pre-commit-config.yaml` file and requires `pre-commit` to be installed and initialized in your repository (via `pre-commit install`).
Install
-
pip install pre-commit -
pre-commit install
Imports
- pre-commit-hooks
This library is not imported directly into Python code. Its hooks are configured in a .pre-commit-config.yaml file for use with the `pre-commit` framework.
Quickstart
# 1. Create a .pre-commit-config.yaml in your repository root
# Example content:
# .pre-commit-config.yaml
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0 # Use the latest version or a specific tag
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
- id: debug-statements
# 2. Install pre-commit (if not already installed)
# pip install pre-commit
# 3. Install the git hooks in your repository
# pre-commit install
# 4. (Optional) Manually run all hooks against all files
# pre-commit run --all-files
# Hooks will now run automatically on `git commit`