# Pre-commit hooks for TypeDialog project
# Install: pre-commit install
# Run manually: pre-commit run --all-files

repos:
  # General file checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: trailing-whitespace
        exclude: '\.md$'
      - id: end-of-file-fixer
      - id: check-yaml
        exclude: '.gitlab-ci.yml'
      - id: check-toml
      - id: check-json
      - id: check-added-large-files
        args: ['--maxkb=1024']
      - id: check-merge-conflict
      - id: mixed-line-ending
        args: ['--fix=lf']

  # Rust formatting
  - 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
        args: ['--all', '--', '--check']

  # Rust linting
  - repo: local
    hooks:
      - id: cargo-clippy
        name: cargo clippy
        entry: cargo clippy
        language: system
        types: [rust]
        pass_filenames: false
        args: ['--all-targets', '--all-features', '--', '-D', 'warnings']

  # Shell script linting
  - repo: https://github.com/shellcheck-py/shellcheck-py
    rev: v0.10.0.1
    hooks:
      - id: shellcheck

  # Markdown syntax linting (docs/ only)
  - repo: https://github.com/DavidAnson/markdownlint-cli2
    rev: v0.20.0
    hooks:
      - id: markdownlint-cli2
        name: markdownlint (syntax)
        files: '^docs/.*\.md$'
        args: ['--config', '.markdownlint-cli2.jsonc']

  # Markdown prose linting with Vale (docs/ only)
  - repo: local
    hooks:
      - id: vale
        name: vale (prose quality)
        entry: bash -c 'vale docs/ || exit 0'
        language: system
        files: '^docs/.*\.md$'
        pass_filenames: false

  # Nickel type checking
  - repo: local
    hooks:
      - id: nickel-typecheck
        name: nickel typecheck
        entry: bash -c 'for f in "$@"; do nickel typecheck "$f" || exit 1; done' --
        language: system
        files: '\.ncl$'
        exclude: '(nickel-secrets|sops-example|conditional|complex|simple|i18n|arrays-schema|nickel-validators)\.ncl$'

  # Nushell script validation
  - repo: local
    hooks:
      - id: nushell-check
        name: nushell check
        entry: bash -c 'for f in "$@"; do nu --ide-check 10 < "$f" > /dev/null || exit 1; done' --
        language: system
        files: '\.nu$'
        exclude: '(json-to-nickel)\.nu$'

  # Security checks
  - repo: local
    hooks:
      - id: cargo-audit
        name: cargo audit
        entry: cargo audit
        language: system
        pass_filenames: false
        stages: [manual]
