Skip to content

A colletion of simple, mostly Python-related pre-commit hooks.

License

Notifications You must be signed in to change notification settings

martinstefanik/pre-commit-hooks

Repository files navigation

Pre-commit hooks

This repo includes a collection of simple pre-commit hooks for Python.

Usage

Add the following to your .pre-commit-config.yaml:

- repo: https://github.com/martinstefanik/pre-commit-hooks
    rev: v1.1.0  # Use the ref you want to point at
    hooks:
    - id: check-multiline-docstrings
    - id: check-module-docstring-space

Available hooks

check-multiline-docstrings

Check that all multiline docstrings in Python files start and end with a single newline character. This checks whether the docstrings are formatted like this

def personalized_greeting(name: str) -> None:
    """
    Personalized greeting printer.

    Args:
        name: Name of the person/entity to greet.
    """
    print(f"Welcome, {name}!")

as opposed for instance to this

def personalized_greeting(name: str) -> None:
    """Personalized greeting printer.

    Args:
        name: Name of the person/entity to greet.
    """
    print(f"Welcome, {name}!")

This might be slightly less common but still conforms to the PEP 257 and some people might prefer docstrings formatted this way.

check-module-docstring-space

Check that the module docstring is separated from the rest of the code by a pre-defined number of empty lines. This is mostly intended to avoid having no space between the module docstring and the imports. This is something the commonly used code formatter Black allows for as of version 2023.9.0.

About

A colletion of simple, mostly Python-related pre-commit hooks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published