# Pre-commit Framework Configuration
# Generated by dev-system/ci
# Configures git pre-commit hooks for Rust projects

repos:
  # ============================================================================
  # Rust Hooks
  # ============================================================================
  - repo: local
    hooks:
      - id: rust-fmt
        name: Rust formatting (cargo +nightly fmt)
        entry: bash -c 'cargo +nightly fmt --all -- --check'
        language: system
        types: [rust]
        pass_filenames: false
        stages: [pre-commit]

      - id: rust-clippy
        name: Rust linting (cargo clippy)
        entry: bash -c 'CARGO_TARGET_DIR=target cargo clippy --all-targets --no-deps --profile clippy -- -D warnings'
        language: system
        types: [rust]
        pass_filenames: false
        stages: [pre-commit]

      - id: rust-test
        name: Rust tests
        entry: bash -c 'cargo test --all-features --workspace'
        language: system
        types: [rust]
        pass_filenames: false
        stages: [pre-commit]

      - id: cargo-deny
        name: Cargo deny (licenses & advisories)
        entry: bash -c 'cargo deny check licenses advisories'
        language: system
        files: Cargo\.(toml|lock)$
        pass_filenames: false
        stages: [pre-commit]

      - id: docs-links
        name: Rustdoc broken intra-doc links
        entry: bash -c 'RUSTDOCFLAGS="-D rustdoc::broken-intra-doc-links -D rustdoc::private-intra-doc-links" cargo doc --no-deps --workspace -q'
        language: system
        types: [rust]
        pass_filenames: false
        stages: [pre-commit]

      - id: docs-drift
        name: Crate //! doc drift check
        entry: bash -c 'nu -c "use ./reflection/modules/sync.nu; sync diff --docs --fail-on-drift"'
        language: system
        types: [rust]
        pass_filenames: false
        stages: [pre-commit]

      - id: manifest-coverage
        name: Manifest capability completeness
        entry: bash -c 'ONTOREF_ROOT="$(pwd)" ONTOREF_PROJECT_ROOT="$(pwd)" nu --no-config-file -c "use ./reflection/modules/sync.nu *; sync manifest-check"'
        language: system
        files: (\.ontology/|reflection/modes/|reflection/forms/).*\.ncl$
        pass_filenames: false
        stages: [pre-commit]

  # ============================================================================
  # Nushell Hooks (optional - enable if using Nushell)
  # ============================================================================
  # - repo: local
  #   hooks:
  #     - id: nushell-check
  #       name: Nushell validation (nu --ide-check)
  #       entry: >-
  #         bash -c 'for f in $(git diff --cached --name-only --diff-filter=ACM | grep "\.nu$"); do
  #         echo "Checking: $f"; nu --ide-check 100 "$f" || exit 1; done'
  #       language: system
  #       types: [file]
  #       files: \.nu$
  #       pass_filenames: false
  #       stages: [pre-commit]

  # ============================================================================
  # Nickel Hooks (optional - enable if using Nickel)
  # ============================================================================
  # - repo: local
  #   hooks:
  #     - id: nickel-typecheck
  #       name: Nickel type checking
  #       entry: >-
  #         bash -c 'export NICKEL_IMPORT_PATH="../:."; for f in $(git diff --cached --name-only --diff-filter=ACM | grep "\.ncl$"); do
  #         echo "Checking: $f"; nickel typecheck "$f" || exit 1; done'
  #       language: system
  #       types: [file]
  #       files: \.ncl$
  #       pass_filenames: false
  #       stages: [pre-commit]

  # ============================================================================
  # Bash Hooks (optional - enable if using Bash)
  # ============================================================================
  # - repo: local
  #   hooks:
  #     - id: shellcheck
  #       name: Shellcheck (bash linting)
  #       entry: shellcheck
  #       language: system
  #       types: [shell]
  #       stages: [pre-commit]
  #
  #     - id: shfmt
  #       name: Shell script formatting
  #       entry: bash -c 'shfmt -i 2 -d'
  #       language: system
  #       types: [shell]
  #       stages: [pre-commit]

  # ============================================================================
  # Markdown Hooks (RECOMMENDED - enable for documentation quality)
  # ============================================================================
  - repo: local
    hooks:
      - id: markdownlint
        name: Markdown linting (markdownlint-cli2)
        entry: markdownlint-cli2
        language: system
        pass_filenames: false
        stages: [pre-commit]

  # ============================================================================
  # General Pre-commit Hooks
  # ============================================================================
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: check-added-large-files
        args: ['--maxkb=1000']
        exclude: (^assets/presentation/|node_modules/)

      - id: check-case-conflict
        exclude: node_modules/

      - id: check-merge-conflict
        exclude: node_modules/

      - id: check-toml
        exclude: (^assets/presentation/|node_modules/)

      - id: check-yaml
        exclude: (^\.woodpecker/|^assets/presentation/|node_modules/)

      - id: end-of-file-fixer
        exclude: (^assets/presentation/|node_modules/)

      - id: trailing-whitespace
        exclude: (\.md$|^assets/presentation/|node_modules/)

      - id: mixed-line-ending
        exclude: (^assets/presentation/|node_modules/)
