https://github.com/rockmagma02/rust-pre-commit-hooks
A set of pre-commit hooks for Rust projects
https://github.com/rockmagma02/rust-pre-commit-hooks
clippy developer-tools pre-commit pre-commit-hook pre-commit-hooks rust rustfmt
Last synced: 7 months ago
JSON representation
A set of pre-commit hooks for Rust projects
- Host: GitHub
- URL: https://github.com/rockmagma02/rust-pre-commit-hooks
- Owner: rockmagma02
- License: mit
- Created: 2024-12-24T15:01:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-24T17:13:10.000Z (about 1 year ago)
- Last Synced: 2025-05-15T15:12:22.622Z (7 months ago)
- Topics: clippy, developer-tools, pre-commit, pre-commit-hook, pre-commit-hooks, rust, rustfmt
- Language: Rust
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust Pre-Commit Hooks
**A set of pre-commit hooks for Rust projects**
[](https://github.com/rockmagma02/rust-pre-commit-hooks/blob/main/LICENSE)
[](https://github.com/rockmagma02/rust-pre-commit-hooks/releases)
[](https://github.com/rockmagma02/rust-pre-commit-hooks/issues)
[](https://github.com/rockmagma02/rust-pre-commit-hooks/pulls)
[](https://pre-commit.com/)

## Table of Contents
- [Implementation](#implementation)
- [Hooks](#hooks)
- [Code Formatting](#code-formatting)
- [Linting](#linting)
- [Example](#example)
- [Known Issues](#known-issues)
- [License](#license)
## 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:
1. Detects all installed Rust toolchains
2. Installs `rustfmt` and `clippy` components for each toolchain
3. 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: `.rs` files
- **rustfmt-check**: Checks if Rust files are properly formatted without modifying them
- ID: `rustfmt-check`
- Runs on: `.rs` files
- **cargo-fmt**: Formats all bin and lib files in the current crate
- ID: `cargo-fmt`
- Runs on entire project
- **cargo-fmt-check**: Checks formatting of all bin and lib files without modifying them
- ID: `cargo-fmt-check`
- Runs on entire project
### Linting
- **clippy**: Runs Clippy lints on all crates in the project
- ID: `clippy`
- Runs on entire project
- **clippy-driver**: Runs Clippy lints on individual Rust files
- ID: `clippy-driver`
- Runs on: `.rs` files
### Example
```yaml
# .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-driver
```
## Known Issues
1. 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.
```bash
pre-commit uninstall
pre-commit clean
pre-commit install
```
2. 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](https://github.com/rockmagma02/rust-pre-commit-hooks/blob/main/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.