default_install_hook_types: [pre-commit, pre-push]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-added-large-files
args: ['--maxkb=1000']
- id: detect-private-key
- id: check-merge-conflict
args: ['--assume-in-merge']
- id: mixed-line-ending
args: ['--fix=lf']
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
exclude: '^Cargo\.lock$'
- repo: local
hooks:
- id: cargo-fmt
name: Format Rust code
description: Check Rust formatting with rustfmt
entry: cargo fmt --all -- --check
language: system
types: [rust]
pass_filenames: false
- id: cargo-check
name: cargo check
entry: cargo check --lib
language: system
types: [rust]
pass_filenames: false
- id: cargo-clippy
name: cargo clippy
entry: cargo clippy --lib
language: system
types: [rust]
pass_filenames: false
args: ['--', '-D', 'warnings']
- id: cargo-test
name: cargo test
entry: cargo test --lib
language: system
types: [rust]
pass_filenames: false
stages: [pre-push]
- id: cargo-coverage
name: cargo coverage (≥95%)
entry: bash -c 'cargo llvm-cov --lib --fail-under-lines 95 2>/dev/null || { echo "→ 先运行 cargo install cargo-llvm-cov"; exit 1; }'
language: system
types: [rust]
pass_filenames: false
stages: [pre-push]
- id: cargo-audit
name: cargo audit (RustSec 漏洞库)
entry: bash -c 'cargo audit 2>/dev/null || { echo "→ 先运行 cargo install cargo-audit"; exit 1; }'
language: system
files: 'Cargo\.lock'
pass_filenames: false
- id: cargo-deny
name: cargo deny check (license/advisory/ban)
entry: bash -c 'cargo deny check 2>/dev/null || { echo "→ 先运行 cargo install cargo-deny && cargo deny init"; exit 1; }'
language: system
files: 'Cargo\.(toml|lock)'
pass_filenames: false
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"