|
| 1 | +# Pre-commit Setup |
| 2 | + |
| 3 | +Pre-commit hooks have been configured to automatically check code quality before each commit. |
| 4 | + |
| 5 | +## Installed Hooks |
| 6 | + |
| 7 | +The following checks run automatically on every commit: |
| 8 | + |
| 9 | +1. **Ruff** - Fast Python linter (checks and fixes issues) |
| 10 | +2. **Black** - Python code formatter |
| 11 | +3. **Mypy** - Static type checker |
| 12 | +4. **Pre-commit hooks** - Trailing whitespace, YAML checks, etc. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +### Automatic (on git commit) |
| 17 | +Hooks run automatically when you commit: |
| 18 | +```bash |
| 19 | +git add <files> |
| 20 | +git commit -m "Your message" |
| 21 | +# Pre-commit hooks will run automatically |
| 22 | +``` |
| 23 | + |
| 24 | +### Manual run on all files |
| 25 | +```bash |
| 26 | +pre-commit run --all-files |
| 27 | +``` |
| 28 | + |
| 29 | +### Manual run on staged files |
| 30 | +```bash |
| 31 | +pre-commit run |
| 32 | +``` |
| 33 | + |
| 34 | +### Run specific hook |
| 35 | +```bash |
| 36 | +pre-commit run ruff --all-files |
| 37 | +pre-commit run black --all-files |
| 38 | +pre-commit run mypy --all-files |
| 39 | +``` |
| 40 | + |
| 41 | +### Skip hooks (not recommended) |
| 42 | +```bash |
| 43 | +git commit --no-verify -m "Skip hooks" |
| 44 | +``` |
| 45 | + |
| 46 | +## Individual Tool Usage |
| 47 | + |
| 48 | +### Ruff |
| 49 | +```bash |
| 50 | +# Check for issues |
| 51 | +ruff check src/ tests/ |
| 52 | + |
| 53 | +# Fix auto-fixable issues |
| 54 | +ruff check --fix src/ tests/ |
| 55 | + |
| 56 | +# Format code |
| 57 | +ruff format src/ tests/ |
| 58 | +``` |
| 59 | + |
| 60 | +### Black |
| 61 | +```bash |
| 62 | +# Check formatting |
| 63 | +black --check src/ tests/ |
| 64 | + |
| 65 | +# Format code |
| 66 | +black src/ tests/ |
| 67 | +``` |
| 68 | + |
| 69 | +### Mypy |
| 70 | +```bash |
| 71 | +# Type check |
| 72 | +mypy src/ |
| 73 | + |
| 74 | +# With ignore missing imports |
| 75 | +mypy src/ --ignore-missing-imports |
| 76 | +``` |
| 77 | + |
| 78 | +## Configuration Files |
| 79 | + |
| 80 | +- `.pre-commit-config.yaml` - Pre-commit hook configuration |
| 81 | +- `pyproject.toml` - Contains Ruff, Black, and Mypy configurations |
| 82 | + |
| 83 | +## What Gets Checked |
| 84 | + |
| 85 | +✅ Code formatting (Black) |
| 86 | +✅ Import sorting (Ruff) |
| 87 | +✅ Linting (Ruff) - unused imports, code quality, etc. |
| 88 | +✅ Type hints (Mypy) |
| 89 | +✅ Trailing whitespace |
| 90 | +✅ End of file fixes |
| 91 | +✅ YAML/TOML syntax |
| 92 | + |
| 93 | +## Installation on New Clones |
| 94 | + |
| 95 | +If you clone this repo elsewhere: |
| 96 | +```bash |
| 97 | +source .venv/bin/activate |
| 98 | +pre-commit install |
| 99 | +``` |
0 commit comments