Files
doczyai-pipelines/documentation/PRE-COMMIT-SETUP.md
T

63 lines
1.5 KiB
Markdown
Raw Normal View History

2026-05-19 20:20:43 +00:00
# Pre-commit Local Setup (uv)
## What is pre-commit?
`pre-commit` runs checks before each commit (for example: formatting and file sanity checks).
This repository uses pre-commit locally only. Bitbucket Pipelines does not run pre-commit.
## Install and set up locally (with uv)
1. Install `uv` (if not installed):
```bash
# Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
```
2. Install all dependencies (including pre-commit):
```bash
uv sync --group dev
```
3. Install git hooks in this repo:
```bash
uv run pre-commit install
```
## How it works
When you run `git commit`, pre-commit automatically runs these checks on your staged files:
| Hook | What it does | Auto-fix? |
|---|---|---|
| `trailing-whitespace` | Removes spaces at end of lines | Yes |
| `end-of-file-fixer` | Ensures files end with a newline | Yes |
| `check-yaml` | Validates YAML syntax | Manual fix |
| `check-json` | Validates JSON syntax | Manual fix |
| `check-merge-conflict` | Detects `<<<<<<<` conflict markers | Manual fix |
| `check-added-large-files` | Blocks files larger than 500KB | Manual fix |
- **Pass** -> commit goes through
- **Fail (auto-fix)** -> commit blocked, files fixed, re-stage and commit again
- **Fail (manual fix)** -> commit blocked, fix the error, re-stage and commit again
## Common commands
Run on all files:
```bash
uv run pre-commit run --all-files
```
Run on staged files (happens automatically on commit):
```bash
uv run pre-commit run
```