Notes to Self

Alex Sokolsky's Notes on Computers and Programming

pre-commit Hook

References:

You can install pre-commit globally or into venv.

Global Installation

Install the toolchain globally:

brew install pre-commit commitizen ripsecrets markdownlint-cli2

On Linux:

sudo apt install pre-commit

In every repository install the hooks:

pre-commit install --hook-type pre-commit --hook-type commit-msg --hook-type pre-push

Create you own version of .pre-commit-config.yaml:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v6.0.0
  hooks:
  - id: check-added-large-files
  - id: check-json
  - id: check-merge-conflict
  - id: check-yaml
  - id: end-of-file-fixer
  - id: trailing-whitespace
    args: [--markdown-linebreak-ext=md]
- repo: https://github.com/sirwart/ripsecrets
  rev: v0.1.11
  hooks:
  - id: ripsecrets
- repo: https://github.com/rhysd/actionlint
  rev: v1.6.25
  hooks:
  - id: actionlint-docker
- repo: https://github.com/commitizen-tools/commitizen
  rev: v4.13.9
  hooks:
  - id: commitizen
  - id: commitizen-branch
    stages: [ pre-push ]
- repo: https://github.com/DavidAnson/markdownlint-cli2
  rev: v0.21.0
  hooks:
  - id: markdownlint-cli2
- repo: local
  hooks:
  - id: Format sources
    name: Run make format
    entry: bash -c "make format && git diff --exit-code"
    language: system
    pass_filenames: false

To uninstall the hooks:

pre-commit uninstall

Installation into venv

When using pre-commit with this repo I bumped into this bug and thought about using pre-commit on this repo from venv:

make pre-commit-install