Skip to content

Add prek hook to forbid banned comment keywords (pragma, type:) #1820

@nathanjmcdougall

Description

@nathanjmcdougall

Problem

Agents (and developers) sometimes add comment annotations that this project doesn't want:

  1. # pragma: no cover — coverage exclusion comments should not be used; instead write tests to cover the code, or remove unreachable branches
  2. # type: ignore[...] — mypy-style type suppression comments; this project uses basedpyright, and any needed type suppressions should use # pyright: ignore[...] instead

These were added in PR #1795 (src/usethis/_file/setup_cfg/deps.py) and caught in code review.

Solution

Add a prek (bespoke) hook that scans Python files and fails if any of these banned keywords are found in comments:

  • pragma: (catches # pragma: no cover and similar)
  • type: ignore (catches # type: ignore[...])

The hook should be provided via CLI, scanning all Python files in src/ and tests/, and report the file/line/column of any violations.

Implementation Notes

  • This should be a bespoke prek hook (see .agents/skills/usethis-prek-hook-bespoke-create/SKILL.md)
  • The hook should accept a list of banned patterns via CLI so it's reusable
  • Should report clear error messages like: src/foo.py:42: Found banned comment keyword 'pragma:'

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions