Skip to content

Commit 8fe8e8d

Browse files
Copilot0xrinegade
andcommitted
Add pre-commit hooks for fmt and clippy checks
Co-authored-by: 0xrinegade <[email protected]>
1 parent 8892486 commit 8fe8e8d

File tree

4 files changed

+108
-5
lines changed

4 files changed

+108
-5
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,45 @@ For complete documentation, visit [our official documentation](https://docs.open
314314

315315
Contributions are welcome! Please feel free to submit a Pull Request.
316316

317+
### Development Setup
318+
319+
To ensure code quality and consistency, this project uses pre-commit hooks that enforce code formatting and linting.
320+
321+
#### Installing Pre-commit Hooks
322+
323+
Run the following command from the project root to install the pre-commit hooks:
324+
325+
```bash
326+
./install-pre-commit-hook.sh
327+
```
328+
329+
This will install a git hook that automatically runs:
330+
- `cargo fmt --all -- --check` - Ensures code is properly formatted
331+
- `cargo clippy` - Runs linting checks
332+
333+
#### Manual Code Quality Checks
334+
335+
You can also run these checks manually:
336+
337+
```bash
338+
# Format your code
339+
cargo fmt --all
340+
341+
# Check formatting without modifying files
342+
cargo fmt --all -- --check
343+
344+
# Run clippy linting
345+
cargo clippy --all-targets --all-features
346+
```
347+
348+
#### Skipping Pre-commit Hooks
349+
350+
If you need to skip the pre-commit hook for a specific commit (not recommended), use:
351+
352+
```bash
353+
git commit --no-verify -m "your message"
354+
```
355+
317356
## πŸ“„ License
318357

319358
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

β€Žinstall-pre-commit-hook.shβ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
#
3+
# Install pre-commit hook for osvm-cli
4+
# This script copies the pre-commit hook to the .git/hooks directory
5+
#
6+
7+
# Check if we're in the right directory
8+
if [ ! -f "Cargo.toml" ] || [ ! -d ".git" ]; then
9+
echo "❌ Error: This script must be run from the root of the osvm-cli repository"
10+
exit 1
11+
fi
12+
13+
# Check if pre-commit script exists
14+
if [ ! -f "pre-commit" ]; then
15+
echo "❌ Error: pre-commit script not found in current directory"
16+
exit 1
17+
fi
18+
19+
# Install the pre-commit hook
20+
echo "πŸ”§ Installing pre-commit hook..."
21+
cp pre-commit .git/hooks/pre-commit
22+
chmod +x .git/hooks/pre-commit
23+
24+
echo "βœ… Pre-commit hook installed successfully!"
25+
echo ""
26+
echo "The hook will now run 'cargo fmt --all -- --check' and 'cargo clippy' before each commit."
27+
echo ""
28+
echo "To skip the pre-commit hook for a specific commit, use:"
29+
echo " git commit --no-verify -m 'your message'"
30+
echo ""
31+
echo "To uninstall the hook, run:"
32+
echo " rm .git/hooks/pre-commit"

β€Žpre-commitβ€Ž

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
#
3+
# Pre-commit hook for osvm-cli
4+
# This hook enforces code formatting and linting before commits
5+
#
6+
7+
set -e
8+
9+
echo "Running pre-commit checks..."
10+
11+
# Check if cargo is available
12+
if ! command -v cargo &> /dev/null; then
13+
echo "Error: cargo is not available. Please install Rust and Cargo."
14+
exit 1
15+
fi
16+
17+
# Run cargo fmt check
18+
echo "πŸ” Checking code formatting..."
19+
if ! cargo fmt --all -- --check; then
20+
echo "❌ Code formatting check failed!"
21+
echo "πŸ’‘ Please run 'cargo fmt --all' to fix formatting issues."
22+
exit 1
23+
fi
24+
echo "βœ… Code formatting is correct"
25+
26+
# Run clippy check (allow it to continue despite known issues, similar to CI)
27+
echo "πŸ” Running clippy checks..."
28+
# Following the same pattern as CI - allowing clippy to continue with known webpki issues
29+
if ! cargo clippy --all-targets --all-features -- -D warnings 2>/dev/null; then
30+
echo "⚠️ Clippy check completed with warnings (some known issues may exist)"
31+
echo "πŸ’‘ Consider reviewing clippy suggestions, but this won't block the commit"
32+
else
33+
echo "βœ… Clippy checks passed"
34+
fi
35+
36+
echo "βœ… All pre-commit checks completed successfully!"
37+
exit 0

β€Žtest_format.rsβ€Ž

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
Β (0)