lint
lint ¶
lint ¶
lint(
check: Callable[[str], list[str]]
| Callable[[AST], Iterator[str]],
*,
message: str,
trigger: str | None = None,
sep: str = ", ",
block: bool = False,
events: Event | None = None,
tests: InlineTests | None = None,
max_shown: int = 5,
) -> None
Register a lint check that runs on Python file edits/writes.
Supports two modes based on the check function's type hint:
- String mode: receives the file content as str, returns violation strings.
- AST mode: receives each ast.AST node, yields violation strings.
Example
def find_prints(content: str) -> list[str]: ... return [line for line in content.splitlines() if "print(" in line] lint(find_prints, message="Remove print statements: {violations}")