Skip to content

refactor(checkers): auto-discover checker modules, drop the barrel#19

Draft
pirr wants to merge 1 commit into
mainfrom
refactor/auto-discover-checkers
Draft

refactor(checkers): auto-discover checker modules, drop the barrel#19
pirr wants to merge 1 commit into
mainfrom
refactor/auto-discover-checkers

Conversation

@pirr

@pirr pirr commented Apr 30, 2026

Copy link
Copy Markdown
Owner

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/.py
  • docs/rules/.md
  • tests/checkers/test_.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.

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.
@pirr pirr self-assigned this Apr 30, 2026
@pirr pirr marked this pull request as draft April 30, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant