refactor(checkers): auto-discover checker modules, drop the barrel#19
Draft
pirr wants to merge 1 commit into
Draft
refactor(checkers): auto-discover checker modules, drop the barrel#19pirr wants to merge 1 commit into
pirr wants to merge 1 commit into
Conversation
Replace the hand-curated list in src/pgsleuth/checkers/__init__.py with a pkgutil-based auto-discovery loop. Every submodule under pgsleuth.checkers (excluding base and any _-prefixed helper) is imported on package load, which runs each module's register(...) call and populates the global registry. Why: every new-checker PR was appending an import to __init__.py, guaranteeing a textual conflict between any two open checker PRs. The barrel was also the single most common new-checker footgun (documented as such in docs/writing_checkers.md): forget the import and the rule is silently invisible. Auto-discovery removes the file that has to be edited and the bug it enabled. Add tests/test_auto_discovery.py with two assertions: - registry is non-empty after import (sanity). - every non-framework module under pgsleuth.checkers has registered at least one Checker (catches the new most-common footgun: forgetting at the bottom of the module). Update docs/writing_checkers.md: drop the 'add to barrel' step, document the auto-discovery convention and the _-prefix escape hatch for non-checker helpers. After this, a new-checker PR touches only: - src/pgsleuth/checkers/<name>.py - docs/rules/<name>.md - tests/checkers/test_<name>.py - README.md (one row in the Checks table) The README is now the only remaining shared file. Conflicts on the Checks table can be eliminated separately by generating it from the registry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the hand-curated list in src/pgsleuth/checkers/init.py with a pkgutil-based auto-discovery loop. Every submodule under pgsleuth.checkers (excluding base and any _-prefixed helper) is imported on package load, which runs each module's register(...) call and populates the global registry.
Why: every new-checker PR was appending an import to init.py, guaranteeing a textual conflict between any two open checker PRs. The barrel was also the single most common new-checker footgun (documented as such in docs/writing_checkers.md): forget the import and the rule is silently invisible. Auto-discovery removes the file that has to be edited and the bug it enabled.
Add tests/test_auto_discovery.py with two assertions:
Update docs/writing_checkers.md: drop the 'add to barrel' step, document the auto-discovery convention and the _-prefix escape hatch for non-checker helpers.
After this, a new-checker PR touches only:
The README is now the only remaining shared file. Conflicts on the Checks table can be eliminated separately by generating it from the registry.