Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 1.68 KB

File metadata and controls

68 lines (49 loc) · 1.68 KB

Pre-commit Hooks Usage

What's Configured

Pre-commit hooks are now set up to automatically check and format code before each commit:

  • Ruff: Python linter and formatter
    • Auto-fixes import sorting and basic issues
    • Formats code to match project style
  • Basic checks: Trailing whitespace, end-of-file, YAML/JSON syntax
  • Pydocstyle: Checks for missing or incorrect docstrings

How It Works

When you run git commit, the hooks will:

  1. ✅ Automatically format your Python code
  2. ✅ Fix trailing whitespace and line endings
  3. ⚠️ Warn about code style issues (line length > 100, missing docstrings)

If hooks modify files, the commit will be aborted so you can review changes. Simply review the changes and commit again.

Manual Commands

# Run all hooks on all files
uv run pre-commit run --all-files

# Run all hooks on staged files only
uv run pre-commit run

# Run specific hook
uv run pre-commit run ruff --all-files
uv run pre-commit run ruff-format --all-files

# Skip hooks for a specific commit (not recommended)
git commit --no-verify

Common Issues

Line Too Long (E501)

Problem: Lines exceed 100 characters Solution: Break long lines manually or ruff will auto-format where possible

Missing Docstrings (D100, D101, D103, etc.)

Problem: Public functions/classes/modules missing docstrings Solution: Add docstrings following Google style:

def my_function(arg1: str) -> dict:
    """Short description of what this does.

    Args:
        arg1: Description of arg1.

    Returns:
        Description of return value.
    """
    pass

Uninstall

To disable pre-commit hooks:

uv run pre-commit uninstall