minimum_pre_commit_version: 4.0.0

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



default_stages: [pre-commit]

ci:

  autofix_prs: false

  autoupdate_schedule: monthly



repos:

  # Basic pre-commit checks

  - 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"]

        exclude: mkdocs\.yml$  # !!python/name: tags incompatible with safe_load

      - id: check-added-large-files

      - id: check-merge-conflict

      - id: detect-private-key

      - id: check-json



  # ---------- Python core checks ----------

  # Ruff: use pre-commit/pyproject.toml

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

    rev: v0.14.14

    hooks:

      - id: ruff-check

        args: ["--config", "pre-commit/pyproject.toml", "--output-format", "github", "--fix"]

        types: [python]

      - id: ruff-format

        args: ["--config", "pre-commit/pyproject.toml"]

        types: [python]



  # codespell: doc/config spelling only; code spelling handled by typos

  - 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",

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

          ]



  # pylint: use 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)

        types: [python]

        args: ["--rcfile=pre-commit/pyproject.toml"]

        verbose: false



  # Bandit: use pre-commit/pyproject.toml

  - repo: https://gitcode.com/gh_mirrors/ba/bandit

    rev: 1.9.4

    hooks:

      - id: bandit

        name: bandit (Python security vulnerability check)

        types: [python]

        args: [

          "--config=pre-commit/pyproject.toml",

          "--quiet",

        ]



  # typos

  - repo: https://gitcode.com/gh_mirrors/ty/typos

    rev: v1.32.0

    hooks:

      - id: typos

        args: ["--force-exclude", "--config", "pre-commit/typos.toml"]



  # C++ core checks

  - 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:

          - "--style=file"  # read .clang-format

          - "--verbose"

          - "-i"



  # ---------- Rust checks (kv-conductor) ----------

  - repo: local

    hooks:

      - id: cargo-fmt

        name: cargo fmt (Rust code formatter)

        entry: cargo fmt --manifest-path motor/kv_conductor/Cargo.toml --all

        language: system

        types: [rust]

        files: ^motor/kv_conductor/

        pass_filenames: false



      - id: cargo-clippy

        name: cargo clippy (Rust linter)

        entry: cargo clippy --manifest-path motor/kv_conductor/Cargo.toml -- -D warnings

        language: system

        types: [rust]

        files: ^motor/kv_conductor/

        pass_filenames: false



  # ======== Local custom hooks ========

  - repo: local

    hooks:

      # --- Header check & cleanup ---

      # Removes useless coding/shebang lines; ensures Mulan PSL v2 license block is present.

      # Excludes pre-commit/ (hook scripts must be executable → need shebang).

      - id: check-header

        name: header check & cleanup

        entry: pre-commit/check_header.py

        language: python

        types: [python]

        exclude: >

          (?x)^(

            pre-commit/|

            build/|

            .*_pb2\.py$|

            .*_pb2_grpc\.py$|

            .*_grpc\.py$|

            .*\.egg-info/|

            .*__pycache__/

          )

        pass_filenames: true



      # --- Modern Python typing ---

      # Detects Optional[X], Dict[K,V], List[X], Tuple[X], Set[X], FrozenSet[X],

      # Type[X], Union[X,Y] and auto-rewrites to Python 3.10+ native syntax.

      # Excludes deployer/ (out of scope).

      - id: check-modern-typing

        name: modern python typing check

        entry: pre-commit/check_modern_typing.py

        language: python

        types: [python]

        exclude: >

          (?x)^(

            deployer/|

            build/|

            .*_pb2\.py$|

            .*_pb2_grpc\.py$|

            .*_grpc\.py$|

            .*\.egg-info/|

            .*__pycache__/

          )

        pass_filenames: true



      # Log quality: basic checks on motor/ production code (incremental; warnings do not block by default)

      - id: log-quality-basic

        name: log quality basic check

        entry: pre-commit/check_log_quality.py --incremental

        language: python

        types: [python]

        files: ^motor/

        exclude: ^motor/.*/tests/

        pass_filenames: true



  # -------------------------- Gitleaks 本地离线二进制扫描 --------------------------

  - repo: local

    hooks:

      - id: gitleaks-offline-scan

        name: Gitleaks Secret Scan(Local Binary)

        entry: ./gitleaks

        language: system

        pass_filenames: true

        args:

          - protect

          - --verbose

          - --redact

          - --config=pre-commit/.gitleaks.toml

        stages: [pre-commit]