AGENT SKILL

Rust 预提交检查

rust-precommit

在每次提交前运行强制性的 PET Rust 预提交检查(cargo fmt + cargo clippy -D warnings)。当即将提交 Rust 更改、应用审查反馈后,或需要验证格式和 lint 是否干净时调用。

使用场景Rust 开发
License 许可
MIT
最近更新
2026-11-10
Stars
★ 209
Forks
48

01 前言 Front Matter

name
rust-precommit
description
Run the mandatory PET Rust pre-commit checks (cargo fmt + cargo clippy -D warnings) before every commit. Invoke whenever you are about to commit Rust changes, after applying review feedback, or whenever you need to verify formatting and lint cleanliness.

03 SKILL.md 正文

Rust Pre-Commit Checks

The PET maintainer workflow requires cargo fmt --all and cargo clippy --all -- -D warnings to pass before every commit. This skill wraps both into a single script invocation.

When to use

  • Before staging any Rust changes for commit.
  • After fixing review comments on a PR, before pushing.
  • Whenever the agent is asked "run pre-commit checks" or "validate the Rust code".

How to run

From the workspace root:

Windows (pwsh)

./scripts/rust-precommit.ps1

macOS / Linux

./scripts/rust-precommit.sh

Both scripts:

  1. Run cargo fmt --all (auto-formats; fails only on unrecoverable errors).
  2. Run cargo clippy --all -- -D warnings (treats warnings as errors).
  3. Exit non-zero on the first failure so callers can gate commits.

Handling failures

  • fmt failure: rare; usually a syntax error preventing parsing. Fix the underlying compile error first.
  • clippy failure: read the diagnostic, fix the code. Do not add #[allow(...)] to suppress unless absolutely justified.
  • After any fix, re-run the script until it reports ALL PRE-COMMIT CHECKS PASSED.

Notes

  • The script must be run from the repository root (or pass the workspace path as the first arg to the .sh variant / -WorkspacePath to the .ps1 variant).
  • Keep the script in sync with .github/copilot-instructions.md "Required Before Committing" section.

04 同仓库更多 Skills