Skip to content

PR 3: Add pre-commit hooks for formatting, linting, and tests#111

Open
natefikru wants to merge 4 commits intomainfrom
nate/pre-commit-hooks
Open

PR 3: Add pre-commit hooks for formatting, linting, and tests#111
natefikru wants to merge 4 commits intomainfrom
nate/pre-commit-hooks

Conversation

@natefikru
Copy link
Copy Markdown

Summary

  • Adds a pre-commit hook (scripts/pre-commit) that runs cargo fmt --check, cargo clippy, and cargo test on staged Rust files
  • Adds make install-hooks target for easy setup and make check to run all checks manually

Test plan

  • Run make install-hooks and verify hook is installed
  • Stage a Rust file and commit to verify the hook fires
  • Run make check to verify all checks pass

Add scripts/pre-commit hook that runs cargo fmt --check and cargo
clippy on staged Rust files before allowing commits. This catches
lint and formatting issues locally before they hit CI.

Add Makefile targets:
- make install-hooks: installs the pre-commit hook
- make check: runs lint + test as a single command
@natefikru natefikru marked this pull request as ready for review March 30, 2026 18:11
Comment on lines +34 to +40
# Run tests
echo " Running tests..."
if ! cargo test; then
echo ""
echo "Tests failed. Fix the failing tests above."
exit 1
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a philosophical debate but pre-commit feels like a weird spot to run tests? Keeping this focused on format/lints feels more optimal; tests aren't instant

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats valid, I'll remove it. I think it is potentially worth adding to projects that are mainly developed using AI but im not sure if that is this one. thanks!

Comment on lines +19 to +25
echo " Checking formatting..."
if ! cargo fmt -- --check; then
echo ""
echo "Formatting check failed. Run 'cargo fmt' to fix."
exit 1
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to rely on make lint, which runs formatting check and clippy already?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason, i wasn't aware of that standard (new to rust) will make the update

Makefile Outdated
Comment on lines +47 to +49
.PHONY: check
check: lint test
@echo "All checks passed."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check is a bit vague, and I don't see this new make target used anywhere in your pre-commit script. Let's remove it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Co-authored-by: Carey Janecka <1709621+figitaki@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants