# pre-commit配置,首次使用需执行以下命令确保生效,可在代码提交前拦截并检查
# pip install pre-commit  # 安装pre-commit工具
# pre-commit install  # 安装git hook,请在代码仓根目录执行
repos:
  # ===================== 通用基础钩子(所有语言) =====================
  #- repo: https://github.com/pre-commit/pre-commit-hooks
  - repo: https://gitcode.com/gh_mirrors/pr/pre-commit-hooks # 使用gitcode镜像加速
    rev: v6.0.0
    hooks:
      - id: trailing-whitespace # 移除行尾空白字符
      - id: end-of-file-fixer # 确保文件以换行符结尾
      - id: check-yaml # 校验 YAML 文件语法
      - id: check-json # 校验 JSON 文件语法
      - id: check-xml # 校验 XML 文件语法
      - id: check-merge-conflict # 检查未解决的合并冲突标记
      - id: check-added-large-files # 拦截超大文件提交(默认500KB)
      #  args: ["--maxkb", "500"]  # 支持自定义修改
      - id: detect-private-key # 检测私钥/敏感信息泄露

  # ===================== 敏感信息扫描 =====================
  #- repo: https://github.com/Yelp/detect-secrets
  - repo: https://gitcode.com/openlibing/pre-commit-hook-gitleaks # 使用openLiBing自建hook
    rev: v8.30.1
    hooks:
      - id: gitleaks

  # ===================== Markdown 文档检查 =====================
  #- repo: https://github.com/DavidAnson/markdownlint-cli2
  - repo: https://gitcode.com/gh_mirrors/ma/markdownlint-cli2 # 使用gitcode镜像加速
    rev: v0.23.1 # 依赖node>=22(engines),流水线setup-node已升级为node 22
    hooks:
      - id: markdownlint-cli2 # 检查Markdown格式与风格,规则集见根目录.markdownlint-cli2.jsonc
  # 格式化
  # 运行前请先本地安装:npm install --save-dev --save-exact prettier@3.9.5
  - repo: local
    hooks:
      - id: prettier-format
        name: prettier format
        entry: npx prettier --write
        language: system
        files: \.(json|yml|yaml|md)$