Skip to content

add precommit hooks for formatting#7

Open
niccokunzmann wants to merge 1 commit into
mainfrom
better-pre-commit
Open

add precommit hooks for formatting#7
niccokunzmann wants to merge 1 commit into
mainfrom
better-pre-commit

Conversation

@niccokunzmann

Copy link
Copy Markdown
Member

This adds a few pre-commit hooks for formatting the code

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add pre-commit hooks for basic formatting and file sanity checks
⚙️ Configuration changes ✨ Enhancement 🕐 Less than 5 minutes

Grey Divider

Description

• Add standard pre-commit hooks for whitespace, EOF, and debug-statement checks.
• Validate common config file formats (JSON/TOML/YAML) before commits.
• Extend existing pre-commit setup alongside the repo’s local hook.
Diagram

graph TD
  Dev[Developer] --> PC["pre-commit"] --> CFG[".pre-commit-config.yaml"] --> Std["pre-commit-hooks"]
  CFG --> Local["local hooks"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Add language-specific formatters/linters via pre-commit (ruff/black/isort, prettier)
  • ➕ Enforces consistent code style beyond whitespace/EOF
  • ➕ Catches more issues earlier (imports, lint, formatting)
  • ➖ Higher friction (more dependencies, longer hook runtime)
  • ➖ Requires agreeing on toolchain and config (pyproject, etc.)
2. Enforce the same checks in CI only (or in addition)
  • ➕ Guaranteed enforcement even if developers skip hooks
  • ➕ Centralized, reproducible checks in PR pipeline
  • ➖ Slower feedback loop than local hooks
  • ➖ Still benefits from local pre-commit for fast iteration

Recommendation: The current approach is a good low-friction baseline for repository hygiene. Consider adding CI enforcement for these checks, and optionally introduce language-specific formatters/linters later if the repo needs stricter style guarantees.

Files changed (1) +13 / -0

Other (1) +13 / -0
.pre-commit-config.yamlEnable upstream pre-commit hygiene hooks +13/-0

Enable upstream pre-commit hygiene hooks

• Adds the 'pre-commit/pre-commit-hooks' repository and enables common checks (debug statements, JSON/TOML/YAML validation, whitespace/EOF fixes, private key detection, and test naming). Keeps the existing local hook configuration intact.

.pre-commit-config.yaml

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 1 rule

Grey Divider


Remediation recommended

1. Prompts checked before unstaged 🐞 Bug ☼ Reliability
Description
The newly added pre-commit-hooks (notably trailing-whitespace / end-of-file-fixer /
detect-private-key) will run before the repo’s unstage-ai-prompts hook, so a staged
.prompts/*.md|*.txt file can be rewritten or cause hook failure even though the project intends to
automatically unstage prompt files before committing.
Code

.pre-commit-config.yaml[R5-16]

+  - repo: https://github.com/pre-commit/pre-commit-hooks
+    rev: v6.0.0
+    hooks:
+      - id: debug-statements
+      - id: check-json
+      - id: check-toml
+      - id: check-yaml
+      - id: destroyed-symlinks
+      - id: detect-private-key
+      - id: end-of-file-fixer
+      - id: name-tests-test
+      - id: trailing-whitespace
Evidence
The repo defines .prompts as the prompt-recording directory and explicitly implements
unstage-ai-prompts to remove .prompts/ files from the git index before committing. Adding
general-purpose formatting/security hooks before the local hooks means staged .prompts/* files can
be processed (and potentially fail) prior to being unstaged.

.pre-commit-config.yaml[5-33]
ai_prompt_auto_commit/unstage.py[11-23]
ai_prompt_auto_commit/common.py[8-20]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New generic `pre-commit-hooks` are added ahead of the local `unstage-ai-prompts` hook. If a user accidentally (or forcibly) stages `.prompts/*.md` or `.prompts/*.txt`, these new hooks can run on those files first, potentially modifying them or failing the commit before the safety hook removes them from the index.

## Issue Context
This repo’s design explicitly includes an `unstage-ai-prompts` pre-commit hook to ensure prompt files are never committed.

## Fix Focus Areas
- .pre-commit-config.yaml[1-33]

## Suggested fix
Add a pre-commit-wide exclude for the prompts directory (or per-hook excludes) so formatting/security checks do not run on `.prompts/**` at all, e.g.:

```yaml
exclude: ^\.prompts/
```

Optionally apply `exclude: ^\.prompts/` per hook if you prefer not to exclude prompts from all hooks.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

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