# Pre-commit configuration compatible with both pre-commit and prek
repos:
  - repo: local
    hooks:
      - id: cargo-fmt
        name: cargo fmt
        entry: cargo fmt --all --
        language: system
        types: [rust]
        pass_filenames: false
        stages: [commit]
        # This automatically fixes formatting issues

      - id: cargo-clippy-fix
        name: cargo clippy fix
        entry: cargo clippy --all-features --all-targets --fix --allow-staged --allow-dirty -- -D warnings
        language: system
        types: [rust]
        pass_filenames: false
        stages: [commit]
        # This automatically fixes clippy warnings where possible

      - id: cargo-clippy
        name: cargo clippy check
        entry: cargo clippy --all-features --all-targets -- -D warnings
        language: system
        types: [rust]
        pass_filenames: false
        stages: [commit]
        # This checks for any remaining clippy warnings that couldn't be auto-fixed

      - id: cargo-nextest
        name: cargo nextest
        entry: cargo nextest run --workspace --all-features
        language: system
        types: [rust]
        pass_filenames: false
        stages: [commit]

      - id: cargo-machete
        name: cargo machete
        entry: cargo machete
        language: system
        types: [toml]
        files: Cargo.toml
        pass_filenames: false
        stages: [commit]

      - id: cargo-audit
        name: cargo audit
        entry: cargo audit
        language: system
        types: [toml]
        files: Cargo.lock
        pass_filenames: false
        stages: [commit]

      - id: cargo-deny
        name: cargo deny check
        entry: cargo deny check
        language: system
        types: [toml]
        files: (Cargo.toml|Cargo.lock|deny.toml)
        pass_filenames: false
        stages: [commit]

      - id: cargo-check
        name: cargo check
        entry: cargo check --workspace --all-features
        language: system
        types: [rust]
        pass_filenames: false
        stages: [commit]

      - id: vscode-lint
        name: VSCode extension lint
        entry: bash -c 'cd vscode-rovo && ( [ -d node_modules ] || npm install ) && npm run lint'
        language: system
        files: ^vscode-rovo/.*\.(ts|js)$
        pass_filenames: false
        stages: [commit]

      - id: vscode-typecheck
        name: VSCode extension type check
        entry: bash -c 'cd vscode-rovo && ( [ -d node_modules ] || npm install ) && npm test'
        language: system
        files: ^vscode-rovo/.*\.(ts|js)$
        pass_filenames: false
        stages: [commit]

      - id: vscode-compile
        name: VSCode extension compile
        entry: bash -c 'cd vscode-rovo && ( [ -d node_modules ] || npm install ) && npm run compile'
        language: system
        files: ^vscode-rovo/.*\.(ts|js)$
        pass_filenames: false
        stages: [commit]

      - id: sync-jetbrains-icon
        name: Sync JetBrains plugin icon
        entry: scripts/sync-jetbrains-icon.sh
        language: system
        files: ^\.docs/rovo-icon\.png$
        pass_filenames: false
        stages: [commit]

  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: trailing-whitespace
        stages: [commit]
      - id: end-of-file-fixer
        stages: [commit]
      - id: check-yaml
        stages: [commit]
      - id: check-toml
        stages: [commit]
      - id: check-merge-conflict
        stages: [commit]
      - id: mixed-line-ending
        args: ["--fix=lf"]
        stages: [commit]
