Skip to content

Add pre-commit hooks for linting and documentation formatting #194

@jeipollack

Description

@jeipollack

Summary

Introduce pre-commit hooks to enforce code and documentation quality automatically before commits. This will improve consistency, reduce CI failures, and streamline development.

Motivation

Currently, formatting and linting are only checked during CI. Adding pre-commit hooks will:

  • Catch style and linting issues locally before pushing
  • Enforce consistent formatting for Python code and documentation
  • Reduce friction during PR reviews

Proposed Hooks

  • Pre-commit hooks for general file checks:

    • check-toml, check-yaml, trailing-whitespace (from pre-commit-hooks)
  • Python linting with Ruff:

    • ruff with --fix and --exit-non-zero-on-fix
    • ruff-format to auto-format code
  • Documentation formatting with Blacken-docs:

    • blacken-docs targeting .rst and .md files
    • Using Black 24.10.0 with line length 120, targeting Python 3.12

Example .pre-commit-config.yaml snippet (from my other project):

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: check-toml
      - id: check-yaml
      - id: trailing-whitespace

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.10.0
    hooks:
      - id: ruff
        args: [--fix, --exit-non-zero-on-fix]
      - id: ruff-format

  - repo: https://github.com/adamchainz/blacken-docs
    rev: 1.19.1
    hooks:
      - id: blacken-docs
        additional_dependencies: [black==24.10.0]
        args: [-l, '120', -t, py312]

Scope

  • Add .pre-commit-config.yaml to the repository
  • Update CONTRIBUTING.md and DEV_WORKFLOW.md with installation instructions
  • Ensure hooks are applied consistently by developers

### Acceptance Criteria

  • Pre-commit hooks run successfully on a fresh clone
  • Developers can install hooks with pre-commit install
  • Documentation clearly explains usage
  • CI passes with hooks enabled locally

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions