Repository navigation
v0.1.0
Table of Contents
Implementation
This project uses a build.rs script to automatically install and configure necessary Rust components (rustfmt and clippy) for all installed toolchains. The build script:
- Detects all installed Rust toolchains
- Installs
rustfmtandclippycomponents for each toolchain - Ensures rustup is properly initialized
This approach ensures that the pre-commit hooks will work correctly regardless of which Rust toolchain you're using.
Hooks
The following pre-commit hooks are available:
Code Formatting
-
rustfmt: Formats individual Rust files using
rustfmt- ID:
rustfmt - Runs on:
.rsfiles
- ID:
-
rustfmt-check: Checks if Rust files are properly formatted without modifying them
- ID:
rustfmt-check - Runs on:
.rsfiles
- ID:
-
cargo-fmt: Formats all bin and lib files in the current crate
- ID:
cargo-fmt - Runs on entire project
- ID:
-
cargo-fmt-check: Checks formatting of all bin and lib files without modifying them
- ID:
cargo-fmt-check - Runs on entire project
- ID:
Linting
-
clippy: Runs Clippy lints on all crates in the project
- ID:
clippy - Runs on entire project
- ID:
-
clippy-driver: Runs Clippy lints on individual Rust files
- ID:
clippy-driver - Runs on:
.rsfiles
- ID:
Example
# .pre-commit-config.yaml
- repo: https://github.com/rockmagma02/rust-pre-commit-hooks
rev: v0.1.0
hooks:
- id: rustfmt
- id: rustfmt-check
- id: cargo-fmt
- id: cargo-fmt-check
- id: clippy
- id: clippy-driverKnown Issues
- When modifying (install new) Rust toolchains, you may need to reinstall the pre-commit hooks to ensure the components (rustfmt and clippy) are properly installed for the new toolchain.
pre-commit uninstall
pre-commit clean
pre-commit install- the clippy-driver hook will compile all lib and bin files in the current crate. Will generate a set of binaries in the root of the project, which we strongly recommend not to use this hook.
License
This project is licensed under the MIT License - see the LICENSE file for details.
The MIT License is a permissive license that allows you to use, modify, and distribute this software for any purpose, provided that the license and copyright notice are included.
Full Changelog: https://github.com/rockmagma02/rust-pre-commit-hooks/commits/v0.1.0