Skip to content

Request: Lint rule to enforce ordering of docstring sections #9641

@stinodego

Description

@stinodego

Here I come again with docstring requests 😅

Our project follows the NumPy docstring conventions outlined here.

One extremely common mistake our contributors make is the order in which docstring sections appear. Often I'll have to correct docstrings where people put the Returns section after the Examples section, or the Notes section before the Warnings section.

Could ruff autodetect/autofix this?

Before

def cool_function() -> int:
    """
    Description.

    Notes
    -----
    Important edge case.

    Warnings
    --------
    Be aware of this requirement!

    Returns
    -------
    int
    """

After

def cool_function() -> int:
    """
    Description.

    Returns
    -------
    int

    Warnings
    --------
    Be aware of this requirement!

    Notes
    -----
    Important edge case.
    """

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationdocstringRelated to docstring linting or formattingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions