Skip to content

fix: error on hooks configured but no matching files - #90

Merged
ineedjet merged 3 commits into
mainfrom
fix/strict-precommit-coverage-check
Jul 2, 2026
Merged

fix: error on hooks configured but no matching files#90
ineedjet merged 3 commits into
mainfrom
fix/strict-precommit-coverage-check

Conversation

@ineedjet

@ineedjet ineedjet commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Converts the extra hooks case from ::notice:: to ::error::, making coverage checking fully bidirectional:

Situation Before After
Files exist, hook missing from .pre-commit-config.yaml FAIL FAIL
Hook configured, no matching files in repo notice FAIL
.pre-commit-config.yaml ≠ workflow linters FAIL FAIL

This enforces that linters, .pre-commit-config.yaml, and actual repo file types are always in full agreement.

🤖 Generated with Claude Code

Previously a ::notice:: — now fails like the inverse case (files exist
but hook missing), enforcing full bidirectional coverage strictness.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ineedjet
ineedjet force-pushed the fix/strict-precommit-coverage-check branch from 500218c to 17c7ada Compare July 2, 2026 22:45
Merge load_hook_defs into needed_hooks, merge load_config +
baseline_configured_hooks into configured_hooks, use walrus
operators for missing/extra checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens the check-precommit-sync enforcement so that .pre-commit-config.yaml, workflow linters, and the repository’s actual file types must remain fully consistent in both directions (missing hooks and superfluous hooks now fail CI).

Changes:

  • Treat “hooks configured but no matching files found” as ::error:: (and fail the check) instead of ::notice::.
  • Refactor hook-definition and repository-file scanning logic for the sync check script.
  • Minor cleanup of subprocess output handling and control flow (:= assignments).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hooks/check-precommit-sync.py Outdated
Comment on lines +26 to +33
def needed_hooks(files):
with open(BASELINE_ROOT / ".pre-commit-hooks.yaml") as f:
hook_defs = yaml.safe_load(f)
return {
h["id"] for h in hook_defs
if ("types" in h and any(set(h["types"]).issubset(file_tags(f)) for f in files))
or ("files" in h and any(re.search(h["files"], str(f)) for f in files))
}
Inlined comprehension was recompiling the regex and recreating the
types set for every file, and changed the types/files priority order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ineedjet
ineedjet merged commit ca0579b into main Jul 2, 2026
1 check 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.

2 participants