# pre-commit配置,首次使用需执行以下命令确保生效,可在代码提交前拦截并检查
# pip install pre-commit  # 安装pre-commit工具
# pre-commit install --install-hooks # 安装git hook,请在代码仓根目录执行

minimum_pre_commit_version: 4.0.0
exclude: |
  (?x)^(
  LICENSES/|
  pre-commit/|
  3rdparty/|
  test/3rdparty/
  )

default_stages: [pre-commit]
ci:
  autofix_prs: false
  autoupdate_schedule: monthly

repos:
  # pre-commit 基础检查
  - repo: https://gitcode.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
        args: ["--allow-multiple-documents"]
      - id: check-added-large-files
      - id: check-merge-conflict
      - id: detect-private-key
      - id: check-json

  # -------------------------- Python 核心检查 --------------------------
  # Ruff:指定读取 pre-commit/pyproject.toml
  - repo: https://gitcode.com/gh_mirrors/ru/ruff-pre-commit
    rev: v0.14.14
    hooks:
      - id: ruff-check
        # 临时跳过 ruff-check,待存量问题修复后恢复
        stages: [manual]
        args:
          [
            "--config",
            "pre-commit/pyproject.toml",
            "--output-format",
            "github",
          ]
        types: [python]
      - id: ruff-format
        args: ["--config", "pre-commit/pyproject.toml"]
        types: [python]

  # codespell:仅提醒,不阻塞提交
  - repo: https://gitcode.com/gh_mirrors/co/codespell
    rev: v2.4.1
    hooks:
      - id: codespell
        entry: bash -c 'codespell "$@" || true' --
        args:
          [
            "-L",
            "CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn,ArchType,AND,ND,tbe,copyin,alog,TE",
            "--skip",
            "*.py,*.cpp,*.hpp,*.c,*.h",
          ]

  # pylint:指定 pre-commit/pyproject.toml
  - repo: https://gitcode.com/gh_mirrors/pyl/pylint
    rev: v4.0.5
    hooks:
      - id: pylint
        name: pylint (Python code quality check)
        # 临时跳过 pylint,待存量问题修复后恢复
        stages: [manual]
        types: [python]
        args: ["--rcfile=pre-commit/pyproject.toml"]
        verbose: false

  # Bandit:指定 pre-commit/pyproject.toml
  - repo: https://gitcode.com/gh_mirrors/ba/bandit
    rev: 1.9.4
    hooks:
      - id: bandit
        name: bandit (Python 安全漏洞检查)
        # 临时跳过 bandit,待存量问题修复后恢复
        stages: [manual]
        types: [python]
        args: ["--config=pre-commit/pyproject.toml", "--quiet"]

  #--------------- C++ 核心检查 ---------------------------------------------
  - repo: https://gitcode.com/pre-commit-clang/mirrors-clang-format
    rev: v18.1.8
    hooks:
      - id: clang-format
        files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx)$
        args:
          # 使用仓库 .clang-format。
          - "--style=file"
          - "--verbose"
          - "-i"
        exclude: ^build/|test/third_party/
  # -------------------------- Gitleaks 二进制扫描 --------------------------
  - repo: https://gitcode.com/GitHub_Trending/gi/gitleaks
    rev: v8.30.1
    hooks:
      - id: gitleaks
        args:
          - git
          - --verbose
          - --redact
          - --config=pre-commit/.gitleaks.toml
        stages: [pre-commit]