# =============================================================================
# 🛠️  PRE-COMMIT CONFIG  - FAST-TIME-SERVER  (Go project)
# =============================================================================
# Install / run:
#   pip install --user pre-commit
#   pre-commit install
#   pre-commit run --all-files
#
# To skip checks:
#   git commit -m "msg" --no-verify
#
# To update:
#   pre-commit autoupdate   # optional: bumps other hooks to latest pinned tags
#   pre-commit install      # (re-installs the git hook if needed)
#   pre-commit run --all-files
# =============================================================================

repos:
  # ---------------------------------------------------------------------------
  # 🔐 Security / secret detection
  # ---------------------------------------------------------------------------
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.27.2
    hooks:
      - id: gitleaks
        name: 🔐 Gitleaks - Detect hard-coded secrets

  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: detect-private-key
        name: 🔐 Detect Private Key
        types: [text]

  # ---------------------------------------------------------------------------
  # ❌ AI artefact & placeholder blockers
  # ---------------------------------------------------------------------------
  - repo: local
    hooks:
      - id: forbid-content-reference
        name: ❌ Forbid :contentReference
        entry: ":contentReference"
        language: pygrep
        types: [text]
        exclude: ^\.pre-commit-config\.yaml$

      - id: forbid-oai-citations
        name: ❌ Forbid OpenAI Citations
        entry: '\[oaicite:\?\?\d+\]'
        language: pygrep
        types: [text]
        exclude: ^\.pre-commit-config\.yaml$

      - id: forbid-ai-stock-phrases
        name: ❌ Forbid AI Stock Phrases
        entry: "(?i)(source=chatgpt.com|turn0search0|brevity| filecite|unchanged|as an ai language model|i am an ai developed by|this response was generated by|i don't have real-time information|i don't have access to real-time|i can't browse the internet|i cannot browse the internet|my knowledge cutoff|my training data|i'm not able to access|i don't have the ability to)"
        language: pygrep
        types: [text]
        exclude: ^\.pre-commit-config\.yaml$

      - id: forbid-placeholder-citations
        name: ❌ Forbid Placeholder Citations
        entry: '\([A-Z][a-z]+,?\s+\d{4}\)'
        language: pygrep
        types: [text]
        exclude: ^\.pre-commit-config\.yaml$

      - id: forbid-source-placeholders
        name: ❌ Forbid Source Placeholders
        entry: '(?i)\(source:'
        language: pygrep
        types: [text]
        exclude: ^\.pre-commit-config\.yaml$

      - id: forbid-malformed-code-fences
        name: ❌ Forbid Malformed Code Fences
        entry: "````+"
        language: pygrep
        types: [text]
        exclude: ^\.pre-commit-config\.yaml$

      - id: warn-ai-transitions
        name: ⚠️ Warn AI Transition Phrases
        entry: "(?i)(brevity|in conclusion,|to summarize,|it is important to note that|remember that|keep in mind that|it's worth noting that|please note that)"
        language: pygrep
        types: [text]
        verbose: true
        exclude: ^\.pre-commit-config\.yaml$

  # ---------------------------------------------------------------------------
  # 🔤 Unicode text normalisation  (smart-quotes, ligatures, exotic spaces)
  # ---------------------------------------------------------------------------
  - repo: https://github.com/sirosen/texthooks
    rev: 0.6.8
    hooks:
      - id: fix-smartquotes
        name: 📝 Normalize Smart Quotes
      - id: fix-ligatures
        name: 🔡 Normalize Ligatures
      - id: fix-spaces
        name: ␣ Normalize Unicode Spaces
      - id: forbid-bidi-controls
        name: 🚫 Forbid BiDi Unicode Controls

  # ---------------------------------------------------------------------------
  # 🧹 Generic formatting & whitespace
  # ---------------------------------------------------------------------------
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: end-of-file-fixer
        name: 🧹 Fix End of Files
        stages: [pre-commit, pre-push, manual]

      - id: trailing-whitespace
        name: 🧹 Trim Trailing Whitespace
        stages: [pre-commit, pre-push, manual]

      - id: fix-byte-order-marker
        name: 🧹 Fix UTF-8 BOM

      - id: mixed-line-ending
        name: 🧹 Mixed Line Ending
        args: [--fix=lf]

      # size / merge / symlink checks
      - id: check-added-large-files
      - id: check-case-conflict
      - id: check-merge-conflict
      - id: check-symlinks
      - id: destroyed-symlinks
      - id: check-executables-have-shebangs
      - id: check-shebang-scripts-are-executable
      - id: forbid-new-submodules
      - id: check-json
      - id: check-yaml
      - id: check-toml
      - id: check-xml
      - id: check-byte-order-marker

  # YAML linter
  - repo: https://github.com/adrienverge/yamllint
    rev: v1.37.1
    hooks:
      - id: yamllint
        name: ✅ yamllint
        args: [-c, .yamllint]
        files: ^.*\.(yml|yaml)$
        exclude: ^charts/

  # CRLF / tab remover
  - repo: https://github.com/Lucas-C/pre-commit-hooks
    rev: v1.5.5
    hooks:
      - id: remove-crlf
        name: 🚀 Remove CRLF
      - id: remove-tabs
        name: 🚀 Remove Tabs
        exclude: '(^|/)Makefile$|\.mk$'

  # ---------------------------------------------------------------------------
  # 🐹 Go tool-chain  (formatters + linters)
  # ---------------------------------------------------------------------------
  - repo: https://github.com/dnephin/pre-commit-golang
    rev: v0.5.1
    hooks:
      # Formatters
      - id: go-fmt
      - id: go-imports
      # Vet / lints
      - id: go-vet
      - id: golangci-lint
      - id: go-lint               # deprecated but kept here intentionally
      - id: go-critic
      # Complexity / metrics
      - id: go-cyclo
        args: ['-over=15']
      # Build & test
      - id: go-build
      - id: go-unit-tests
      # Module hygiene
      - id: go-mod-tidy
      # Misc checks
      - id: validate-toml
      - id: no-go-testing

  - repo: https://github.com/segmentio/golines
    rev: v0.12.2
    hooks:
      - id: golines
        name: 🧹 golines - wrap long lines
        args: ["--max-len=120", "--base-formatter=gofumpt"]

  # ---------------------------------------------------------------------------
  # 📝 OPTIONAL / web / extras (commented-out, keep for future)
  # ---------------------------------------------------------------------------
  #
  # - repo: https://github.com/pre-commit/mirrors-prettier
  #   rev: v3.0.3
  #   hooks:
  #     - id: prettier
  #
  # - repo: https://github.com/igorshubovych/markdownlint-cli
  #   rev: v0.45.0
  #   hooks:
  #     - id: markdownlint
