Skip to content

Latest commit

 

History

History
96 lines (64 loc) · 2 KB

File metadata and controls

96 lines (64 loc) · 2 KB

Pre-commit Setup Guide

This repository uses pre-commit hooks to automatically format code on every commit.

Formatters Used

  • Ruff: Fast Python linter and formatter (replaces Black, isort, and flake8)
  • Prettier: Code formatter for JavaScript, TypeScript, JSON, YAML, and Markdown

Initial Setup

  1. Install dependencies (if not already installed):

    pip install -r requirements-dev.txt

    Or install individually:

    pip install pre-commit ruff
  2. Install pre-commit hooks:

    pre-commit install

    This will set up the git hooks to run automatically on every commit.

  3. Optional: Run on all files (to format existing code):

    pre-commit run --all-files

How It Works

Once installed, pre-commit will automatically:

  • Format Python code with Ruff before each commit
  • Format JavaScript/TypeScript/JSON/YAML/Markdown files with Prettier
  • Check for trailing whitespace, end-of-file issues, and other common problems
  • Prevent committing if there are formatting issues

Manual Usage

You can also run the formatters manually:

# Run all hooks on staged files
pre-commit run

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

# Run a specific hook
pre-commit run ruff --all-files
pre-commit run prettier --all-files

Configuration Files

  • .pre-commit-config.yaml: Pre-commit hooks configuration
  • pyproject.toml: Ruff configuration (Python formatting and linting)
  • .prettierrc: Prettier configuration (JavaScript/TypeScript formatting)
  • .prettierignore: Files to exclude from Prettier formatting

Updating Hooks

To update pre-commit hooks to their latest versions:

pre-commit autoupdate

Troubleshooting

If hooks fail, you can:

  1. Skip hooks for a specific commit (not recommended):

    git commit --no-verify
  2. Update hook versions:

    pre-commit autoupdate
  3. Clear pre-commit cache:

    pre-commit clean