# Local pre-commit hooks. Install once with:
#   pip install pre-commit
#   pre-commit install
#
# After install: every `git commit` runs these checks against staged files.
# Failures abort the commit.

repos:
  # Generic hygiene
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
        exclude: ^backend/alembic/script.py.mako$
      - id: check-toml
      - id: check-added-large-files
        args: ["--maxkb=512"]
        # #1966: the frozen backtest regression-gate fixture is gzipped prod
        # inputs (~3 MB). It is re-extracted rarely (only when ground-truth
        # refreshes), so it does not bloat history per estimator change — the
        # per-change artifact is the 3 KB backtest_baseline.json.
        exclude: ^tradein-mvp/backend/tests/fixtures/backtest_full_fixture\.json\.gz$
      - id: check-merge-conflict
      - id: detect-private-key

  # Python — ruff (lint + format) on backend/ + tradein-mvp/backend/
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.7.4
    hooks:
      - id: ruff
        args: [--fix]
        files: ^(backend|tradein-mvp/backend)/
      - id: ruff-format
        files: ^(backend|tradein-mvp/backend)/

  # Frontend — prettier on TS/TSX/JSON.
  # additional_dependencies pins the EXACT prettier engine (3.9.0) so this hook
  # and CI (`openapi-codegen-check` → ./node_modules/.bin/prettier, also 3.9.0
  # via frontend/package.json) format byte-for-byte identically. Без явного pin
  # mirrors-prettier@v4.0.0-alpha.8 тянет CLI-обёртку, а CI `npx prettier`
  # плавает в latest → расхождение формата → codegen-gate RED. Меняешь версию
  # здесь — синхронно меняй prettier в frontend/package.json + lockfile.
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v4.0.0-alpha.8
    hooks:
      - id: prettier
        additional_dependencies: ["prettier@3.9.0"]
        files: ^frontend/.*\.(ts|tsx|js|jsx|json|css|md)$
        exclude: ^frontend/(node_modules|\.next|package-lock\.json)/
