R342 Run a Python project’s lint and lock file check in the commit hooks

On by default

Run the formatter, linter and docstring checker that a Python project configures, and the check that its lock file is current, in the repository’s commit hooks.

Reason

A check that runs only when someone remembers to run it catches mistakes only then; in the hooks, these fast checks stop a mistake before it is committed (Art. III §1(2)). The type check and the tests stay out of the hooks, which rule 250 keeps to checks that take seconds.

Verification

What the hooks run is read from their configuration. A project configures a tool when the tool is in its dependency groups with settings for it; whether a project must have a docstring checker at all is for rule 341, not this rule. The lock file check is one that fails when the lock file no longer matches the project file, such as the uv-lock hook; a project that keeps no lock file needs none. A gap that is already there when a repository enables this rule is broken only by a change that touches it, as below, so that unrelated changes are not in breach.

Violated when a change adds a Python project, adds a formatter, linter or docstring checker to one, or changes the commit hook configuration, and after the change the hooks do not run one of these checks, or the lock file check, for a Python project in the repository.

Provisions of the constitution it cites

Relations

Parent
R339 Python
Requires
none
Conflicts with
none

Metadata

ID
342
Revision
1
Kind
rule
Status
trial
Slug
python-lint-in-hooks
Default level
project
Constitution revisions
>=1
Check
none
Default
on
Uses
Instructions instructions, Review review
Original language
English en
Translations
Chinese zh