|
| 1 | +# Pre-commit hooks configuration for Penn Marketplace |
| 2 | +# See https://pre-commit.com for more information |
| 3 | +# |
| 4 | +# Setup: pip install pre-commit && pre-commit install |
| 5 | +# Or: cd backend && uv run pre-commit install |
| 6 | +# |
| 7 | +# Run manually: pre-commit run --all-files |
| 8 | +# Run same checks as CI: ./scripts/check.sh |
| 9 | + |
| 10 | +repos: |
| 11 | + # ============================================================================= |
| 12 | + # General file checks (fast, always run) |
| 13 | + # ============================================================================= |
| 14 | + - repo: https://github.com/pre-commit/pre-commit-hooks |
| 15 | + rev: v4.6.0 |
| 16 | + hooks: |
| 17 | + - id: trailing-whitespace |
| 18 | + exclude: ^(.*\.lock|.*\.min\.js|.*\.min\.css) |
| 19 | + - id: end-of-file-fixer |
| 20 | + exclude: ^(.*\.lock|.*\.min\.js|.*\.min\.css) |
| 21 | + - id: check-yaml |
| 22 | + - id: check-json |
| 23 | + - id: check-toml |
| 24 | + - id: check-added-large-files |
| 25 | + args: ['--maxkb=1000'] |
| 26 | + |
| 27 | + # ============================================================================= |
| 28 | + # Backend: Python formatting and linting |
| 29 | + # ============================================================================= |
| 30 | + # Note: CI uses ruff format (not Black), so we match that in pre-commit |
| 31 | + - repo: https://github.com/astral-sh/ruff-pre-commit |
| 32 | + rev: v0.8.4 |
| 33 | + hooks: |
| 34 | + - id: ruff |
| 35 | + name: ruff check (Python linter) |
| 36 | + files: ^backend/.*\.py$ |
| 37 | + args: ['--fix'] # Auto-fix what can be fixed |
| 38 | + - id: ruff-format |
| 39 | + name: ruff format (Python formatter) |
| 40 | + files: ^backend/.*\.py$ |
| 41 | + # Auto-formats (standard pre-commit behavior) |
| 42 | + |
| 43 | + # ============================================================================= |
| 44 | + # Frontend: Formatting and linting via local commands |
| 45 | + # (Uses your installed pnpm/node for better compatibility) |
| 46 | + # ============================================================================= |
| 47 | + - repo: local |
| 48 | + hooks: |
| 49 | + - id: frontend-prettier |
| 50 | + name: prettier (frontend) |
| 51 | + entry: bash -c 'cd frontend && pnpm format' |
| 52 | + language: system |
| 53 | + files: ^frontend/.*\.(ts|tsx|js|jsx|json|css|md)$ |
| 54 | + pass_filenames: false |
| 55 | + # Auto-formats (standard pre-commit behavior) |
| 56 | + |
| 57 | + - id: frontend-eslint |
| 58 | + name: eslint (frontend) |
| 59 | + entry: bash -c 'cd frontend && pnpm lint:fix' |
| 60 | + language: system |
| 61 | + files: ^frontend/.*\.(ts|tsx|js|jsx)$ |
| 62 | + pass_filenames: false |
| 63 | + # Auto-fixes what can be fixed |
| 64 | + |
| 65 | + - id: frontend-typecheck |
| 66 | + name: TypeScript type check (frontend) |
| 67 | + entry: bash -c 'cd frontend && pnpm typecheck' |
| 68 | + language: system |
| 69 | + files: ^frontend/.*\.(ts|tsx)$ |
| 70 | + pass_filenames: false |
| 71 | + # Type checking (whole project, but runs on commit) |
| 72 | + |
| 73 | +# ============================================================================= |
| 74 | +# Notes: |
| 75 | +# - Pre-commit hooks AUTO-FIX issues (convenient for developers) |
| 76 | +# - check.sh only CHECKS (use --fix flag to auto-fix) |
| 77 | +# - TypeScript type checking runs in both pre-commit and check.sh |
| 78 | +# - CI doesn't run TypeScript explicitly (Next.js build catches type errors) |
| 79 | +# - CI uses ruff format (not Black), so pre-commit matches that |
| 80 | +# - Frontend: CI and pre-commit both use pnpm |
| 81 | +# ============================================================================= |
0 commit comments