style.styleguide()
Register one change-scoped hook applying the given style rules to Python edits and writes.
Usage
style.styleguide(
*rules, block=False, only_if=(), skip_if=(), events=None, max_shown=5
)Each rule is a [StyleRule][captain_hook.style.StyleRule] (or [StyleDiffRule][captain_hook.style.StyleDiffRule]) subclass whose docstring is its message. The single registered hook parses the edited file once, runs every rule against the post-edit tree, scopes each violation to the changed lines, and emits one aggregated warning (or block, when block is set). Call again with different only_if / skip_if / events / block to register a separately scoped hook.
Parameters
rules: type[StyleRule] = ()-
StyleRule / StyleDiffRule subclasses to apply.
block: bool = False-
Block the tool call instead of warning.
only_if: Sequence[TCondition] = ()-
Extra conditions ANDed onto the built-in
Edit|Write+*.pyguards. skip_if: Sequence[TCondition] = ()-
Extra conditions ORed onto the built-in test-file skip.
events: Event | None = None-
Override the default PostToolUse targeting.
max_shown: int = 5- Maximum violations shown per rule.
Example
styleguide(NoPrint, NoBareExcept) styleguide(NoSqlInjection, block=True, only_if=[FilePath(“api/**/*.py”)])