If you are unfamiliar with pre-commit hooks, see their website: https://pre-commit.com/.
These hooks are tested with Python 3.11-3.15. The hooks use bash scripts, so is tested and run on Ubuntu. It may work with other Python versions or operating systems (such as MacOS or WSL).
Check dbg expressions/statements have been removed from Rust/Python/C++/CUDA/other files.
It also checks for #included <dbg.h> or from debug import dbg imports. (see https://github.com/George-Ogden/dbg).
Find any "todo"s or "fixme"s or "deleteme"s that are left in your source code.
It checks comments and code, such as todo!() or # TODO: ....
Any words that contain either of these phrases are ignored (such as "photodocumentary").
Hidden files are ignored.
List all untracked files and directories. If there are any untracked files, they will be listed alongside a warning. If there are none, nothing happens. This hook always passes, unless there is an internal error.
Ensure all C++/CUDA headers contain #pragma once.
This doesn't have to be the first line, but it must come before any #include ... statements.
Run ty in an environment with dependencies.
It allows you to pass in a dependency group using the -g or --group flag (installed via uv). Any additional flags are passed to the ty executable (no defaults). If no dependency group is specified, it defaults to the types group.
This hook does not accept filenames as an argument - it runs on all the files on every commit. This means to exclude files, you must use the --exclude flag instead of the builtin exclude key.
It requires that you have pip or uv installed, but if you're using pre-commit or prek, that shouldn't be an issue.
Check that there are no absolute imports from a specific module.
This defaults to src, but you can set a custom module with the --disallowed-module flag.
If you have scripts, you may want to exclude these, by default only __main__.py files are excluded.
See the pre-commit documentation to exclude other files as well.
[If you] make spelling mistakes in commit messages, it's then a real pain to amend the commit. And god forbid if you pushed.
This uses codespell under the hood, and accepts the same flags via the args field, but interactive mode is not supported.
You need to ensure that you install the commit-msg hooks, which you can do with pre-commit install -t pre-commit -t commit-msg or adding default_install_hook_types: [pre-commit, commit-msg] to the .pre-commit-config.yaml (like below).
This hook writes a specific message when you change version.txt: "Bump version X.X.X -> Y.Y.Y".
It only works when you give it no message explicitly via git commit -m "" or git commit --no-edit.
You need to ensure that you install the prepare-commit-msg hooks, which you can do with pre-commit install -t pre-commit -t prepare-commit-msg or adding default_install_hook_types: [pre-commit, prepare-commit-msg] to the .pre-commit-config.yaml (like below).
Automatically add a message about modifying the mirror.lock.
"Sync mirror" is added when you change .mirror.lock and "Install mirror" when you create it.
See mirror-rorrim for more information about mirror files.
It only works when you give it no message explicitly via git commit -m "" or git commit --no-edit.
You need to ensure that you install the prepare-commit-msg hooks, which you can do with pre-commit install -t pre-commit -t prepare-commit-msg or adding default_install_hook_types: [pre-commit, prepare-commit-msg] to the .pre-commit-config.yaml (like below).
Here's a sample .pre-commit-config.yaml:
default_stages: [pre-commit]
default_install_hook_types: [pre-commit, prepare-commit-msg, commit-msg]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/George-Ogden/linter
rev: v1.2.1
hooks:
- id: lint
exclude: ^tests/[^/].*/test_data/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.2
hooks:
- id: ruff-format
- id: ruff
args:
- --fix
- repo: https://github.com/George-Ogden/pre-commit-hooks/
rev: v5.1.0
hooks:
- id: dbg-check
exclude: ^test/
- id: todo-check
exclude: README
- id: pragma-once
- id: absolute-imports-check
- id: ty
args: [--exclude, test_samples/]
- id: spell-check-commit-msgs
- id: version-txt-auto-msg
- id: mirror-auto-msg
- id: list-untracked-importsUse the GitHub issue tracker for bugs/feature requests. I made these hooks because I use them, can't find them somewhere else, and find them valuable during developing other software. I hope you can make use of them too!