Skip to content

feat: Add pre-commit hooks for lint and tests#28

Merged
kodroi merged 1 commit intomainfrom
feat/husky-pre-commit
Feb 21, 2026
Merged

feat: Add pre-commit hooks for lint and tests#28
kodroi merged 1 commit intomainfrom
feat/husky-pre-commit

Conversation

@kodroi
Copy link
Copy Markdown
Owner

@kodroi kodroi commented Feb 21, 2026

Summary

  • Adds .pre-commit-config.yaml with local hooks for ruff (lint + autofix), mypy (type check), and pytest (tests) — runs before every commit
  • Adds pre-commit to dev dependencies in pyproject.toml
  • Fixes ruff SIM114 lint violation in protect_directories.py (combined duplicate if branches)

Setup

pip install -e ".[dev]"
pre-commit install

Test plan

  • pre-commit run --all-files passes locally
  • CI lint and tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Introduced pre-commit configuration with automated linting, type checking, and testing hooks.
  • Improvements

    • Enhanced file operation detection for in-place edit commands.

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 21, 2026

📝 Walkthrough

Walkthrough

Introduces 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

Cohort / File(s) Summary
Pre-commit Framework Setup
.pre-commit-config.yaml, pyproject.toml
Adds pre-commit configuration with local hooks for ruff, mypy, and pytest; includes pre-commit dependency in dev optional dependencies.
Sed In-Place Detection Logic
hooks/protect_directories.py
Broadens in-place file-detection condition in get_bash_target_paths to treat any argument starting with --in-place or short flags containing "i" (e.g., -i, -wi) as enabling in-place edits.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops to commit with care,
Ruff and mypy dance through the air,
Sed's patterns bloom with graceful sway,
Pre-commit guards each line today! 🎀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding pre-commit hooks for linting and testing, which matches the core objective of introducing .pre-commit-config.yaml with ruff, mypy, and pytest hooks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/husky-pre-commit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.pre-commit-config.yaml (1)

16-21: Consider deferring the pytest hook to the pre-push stage.

always_run: true with the default pre-commit stage 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.

@kodroi kodroi merged commit bc1a912 into main Feb 21, 2026
13 checks passed
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.

1 participant