pre-commit==4.3.0
black==25.9.0
isort==5.13.1
ruff==0.13.2
flake8==7.3.0
flake8-bugbear==23.9.0
flake8-docstrings==1.7.0
pylint==3.2.6
mypy==1.16.0
bandit==1.8.6
detect-secrets==1.4.0
commitizen==4.8.1
default_install_hook_types: [pre-commit, commit-msg, pre-push]
repos:
# ------------------------------
# Housekeeping
# ------------------------------
- repo: local
hooks:
- id: trailing-whitespace
name: Trim trailing whitespace
entry: bash -c "sed -i 's/[ \t]*$//' \"$@\"" --
language: system
files: .*\.(py|md|txt|yaml|yml|json)$
- id: end-of-file-fixer
name: Ensure file ends with newline
entry: bash -c "[[ -f \"$1\" ]] && sed -i -e '\$a\\' \"$@\"" --
language: system
files: .*\.(py|md|txt|yaml|yml|json)$
- id: check-yaml
name: Check YAML files
entry: python -c "import sys, yaml; [yaml.safe_load(open(f)) for f in sys.argv[1:]]"
language: system
files: \.(yaml|yml)$
- id: check-json
name: Check JSON files
entry: python -c "import sys, json; [json.load(open(f)) for f in sys.argv[1:]]"
language: system
files: \.(json)$
- id: check-added-large-files
name: Prevent committing large files (>5MB)
entry: bash -c 'for f in "$@"; do if [ -f "$f" ] && [ $(stat -c%s "$f") -gt 5242880 ]; then echo "❌ Large file detected: $f"; exit 1; fi; done' --
language: system
files: .*
# ------------------------------
# Formatters
# ------------------------------
- repo: local
hooks:
- id: black
name: black
entry: black
language: system
types: [python]
args: [--check, --diff]
- id: isort
name: isort
entry: isort
language: system
types: [python]
args: [--check-only, --diff]
# ------------------------------
# Linters
# ------------------------------
- repo: local
hooks:
- id: ruff
name: ruff
entry: ruff
language: system
types: [python]
args: [--fix]
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args: [--errors-only, --jobs=4]
# ------------------------------
# Typing
# ------------------------------
- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
args: [--ignore-missing-imports]
# ------------------------------
# Security
# ------------------------------
- repo: local
hooks:
- id: bandit
name: bandit
entry: bandit
language: system
types: [python]
args: [-r, .]
- id: detect-secrets
name: detect-secrets
entry: detect-secrets
language: system
types: [text]
args: ['--baseline', '.secrets.baseline']
stages: [commit]
# ------------------------------
# Commit message checks
# ------------------------------
- repo: local
hooks:
- id: commitizen
name: commitizen
entry: cz
language: system
stages: [commit-msg]
args: [check]
pre-commit install # installs pre-commit hook
pre-commit install --hook-type commit-msg # enforces commitizen rules
pre-commit install --hook-type pre-push # for push-time checks
pre-commit run --all-files
⚙️ 4. Secrets baseline (for detect-secrets)
Initialize a baseline file (checked into repo):
This ensures secrets are tracked consistently.
⚙️ 5. Commitizen config
Add pyproject.toml
or .cz.toml
:
Now you can commit like:
Comments
Post a Comment