# Pre-commit hooks for code quality # Install: pip install pre-commit # Setup: pre-commit install # Run manually: pre-commit run --all-files # # Ruff handles linting and formatting (black). It does NOT sort imports here: # `I` is absent from `select` in pyproject.toml, so import order is unchecked # by the hook and by CI alike. Enabling it is a one-time reformat of 46 files # and is still open (#1496). # # The `rev` below must equal the `ruff==` pin in the dev extra of # pyproject.toml, which is the ruff CI installs. Two pins are two formatters; # tests/unit/test_pre_commit_ruff_matches_the_dev_pin.py fails when they drift. repos: # Ruff - Fast Python linter + formatter (replaces black and flake8) - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.16.7 hooks: - id: ruff name: ruff check (lint, no import sorting) args: ["--fix"] files: ^(src|tests)/ - id: ruff-format name: ruff format files: ^(src|tests)/ # Markdown linting - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.43.0 hooks: - id: markdownlint args: ["--fix", "--config", ".markdownlint.json"] files: \.(md|markdown)$ exclude: ^\.planning/ # Built-in pre-commit hooks - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml args: ["--unsafe"] # Allow custom YAML tags exclude: '^(deploy/helm|packages/helm-charts)/.*/templates/.*\.yaml$' # Exclude Helm templates - id: check-added-large-files args: ["--maxkb=500"] - id: check-json - id: check-toml - id: check-merge-conflict - id: debug-statements - id: mixed-line-ending # Changelog fragments. Cheap here, and the alternative is finding a malformed # fragment during release assembly -- on the release branch, with the release # waiting on it. - repo: local hooks: - id: changelog-fragments name: validate changelog fragments entry: python scripts/build_changelog.py check language: system pass_filenames: false files: ^changelog\.d/ # Pytest check (optional - runs fast tests) # Uncomment if you want tests to run on commit # - repo: local # hooks: # - id: pytest-check # name: pytest-check # entry: pytest # language: system # pass_filenames: false # always_run: true # args: ['-m', 'not slow', '--tb=short']