# ---------------------------------------------------------------------------------------------------------

# Copyright (c) 2026 Huawei Technologies Co., Ltd.

# This program is free software, you can redistribute it and/or modify it under the terms and conditions of

# CANN Open Software License Agreement Version 2.0 (the "License").

# Please refer to the License for details. You may not use this file except in compliance with the License.

# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,

# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

# See LICENSE in the root of the software repository for the full text of the License.

# ---------------------------------------------------------------------------------------------------------

minimum_pre_commit_version: 4.0.0

exclude: ^LICENSES/|\.(html|csv|svg)$



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



  # C++ 代码格式化检查

  - repo: https://gitcode.com/pre-commit-clang/mirrors-clang-format

    rev: v22.1.5

    hooks:

      - id: clang-format

        files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|asc)$

        args:

          - "--style=file"

          - "--verbose"

          - "-i"

        exclude: ^build/|tests/third_party/



  # Python 代码检查

  - repo: https://gitcode.com/gh_mirrors/ru/ruff-pre-commit

    rev: v0.14.14

    hooks:

      - id: ruff-check

        args: ["--output-format", "github", "--fix"]

        types: [python]

      - id: ruff-format

        types: [python]



  # 拼写检查

  - repo: https://gitcode.com/gh_mirrors/co/codespell

    rev: v2.4.1

    hooks:

      - id: codespell

        args: [

            "-L",

            "CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn,ArchType,AND,ND,tbe,copyin,alog",

            "--skip",

            "*.py,*.cpp,*.hpp,*.c,*.h",

          ]



  # OAT 合规性检查 (Open Source Audit Tool)

  - repo: local

    hooks:

      - id: oat-check

        name: OAT Compliance Check

        entry: bash scripts/oat_check.sh

        language: system

        pass_filenames: true

        types: [file]

        stages: [pre-commit]

        verbose: true