feat: Add pre-commit hooks for lint and tests#28
Conversation
Adds .pre-commit-config.yaml with local hooks that run ruff check, mypy type checking, and pytest before each commit. Also fixes a ruff SIM114 lint violation in protect_directories.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughIntroduces a new pre-commit configuration file with hooks for ruff (linting), mypy (type checking), and pytest (testing), along with corresponding dependency addition. Simultaneously updates sed in-place edit detection logic to broaden the set of recognized argument patterns. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.pre-commit-config.yaml (1)
16-21: Consider deferring the pytest hook to thepre-pushstage.
always_run: truewith the defaultpre-commitstage means the full test suite runs on every commit, including trivial changes (docs, comments, config). As the test suite grows this will noticeably hurt commit latency.Using a pre-push hook for more time-intensive checks and pushing multiple commits at once is the standard pattern for test suites. Moving pytest to
stages: [pre-push]requires installing that hook type once (pre-commit install --hook-type pre-push), but lets developers commit freely and only gate on push.♻️ Suggested change
- id: pytest name: pytest entry: python -m pytest tests/ -x -q language: system pass_filenames: false - always_run: true + stages: [pre-push]Then update the setup instructions:
pre-commit install --hook-type pre-commit --hook-type pre-push🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.pre-commit-config.yaml around lines 16 - 21, The pytest hook currently runs on every commit due to always_run: true; change the pytest hook (id: pytest, entry: python -m pytest tests/ -x -q) to run at pre-push by adding stages: [pre-push] and removing or setting always_run to false so tests no longer run on every commit, and update the developer setup instructions to tell users to install both hooks (pre-commit and pre-push) using pre-commit install --hook-type pre-commit --hook-type pre-push.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.pre-commit-config.yaml:
- Around line 16-21: The pytest hook currently runs on every commit due to
always_run: true; change the pytest hook (id: pytest, entry: python -m pytest
tests/ -x -q) to run at pre-push by adding stages: [pre-push] and removing or
setting always_run to false so tests no longer run on every commit, and update
the developer setup instructions to tell users to install both hooks (pre-commit
and pre-push) using pre-commit install --hook-type pre-commit --hook-type
pre-push.
Summary
.pre-commit-config.yamlwith local hooks for ruff (lint + autofix), mypy (type check), and pytest (tests) — runs before every commitpre-committo dev dependencies inpyproject.tomlprotect_directories.py(combined duplicateifbranches)Setup
pip install -e ".[dev]" pre-commit installTest plan
pre-commit run --all-filespasses locally🤖 Generated with Claude Code
Summary by CodeRabbit
Chores
Improvements