# Pre-commit hooks for Rust projects
# Install: pip install pre-commit
# Setup: pre-commit install
# Run manually: pre-commit run --all-files

repos:
  - repo: local
    hooks:
      # Rust formatting
      - id: cargo-fmt
        name: cargo fmt
        description: Format Rust code with rustfmt
        entry: cargo fmt --all --
        language: system
        types: [rust]
        pass_filenames: false

      # Rust linting
      - id: cargo-clippy
        name: cargo clippy
        description: Lint Rust code with clippy
        entry: cargo clippy --workspace --all-features -- -D warnings
        language: system
        types: [rust]
        pass_filenames: false

      # Security audit
      - id: cargo-audit
        name: cargo audit
        description: Check for security vulnerabilities
        entry: bash -c 'command -v cargo-audit >/dev/null 2>&1 && cargo audit || echo "cargo-audit not installed, skipping"'
        language: system
        types: [rust]
        pass_filenames: false

      # Cargo check
      - id: cargo-check
        name: cargo check
        description: Check Rust code compilation
        entry: cargo check --workspace --all-features
        language: system
        types: [rust]
        pass_filenames: false

  # General file checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-toml
      - id: check-merge-conflict
      - id: check-case-conflict
      - id: detect-private-key

  # TOML formatting
  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
    rev: v2.12.0
    hooks:
      - id: pretty-format-toml
        args: [--autofix]
