ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Automatically wrap certain simple docstrings

Open kurtbuilds opened this issue 3 years ago • 1 comments

Automatic line length wrapping is a huge can of worms.

This PR starts to address one isolated case where we can automatically solve line length wrapping, namely for some docstrings. Example:

class Account:
    address: str = None
    """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."""

is automatically corrected to

class Account:
    address: str = None
    """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua."""

I'm guessing there's more checking that needs to happen (e.g. this might wrap things that we don't want, like reStructuredText values). This PR serves as a starting point.

kurtbuilds avatar Nov 26 '22 18:11 kurtbuilds

I'm a little hesitant on this fix because splitting the first line across multiple lines creates some other lint errors 🤔 Namely, the first line is expected to be a single line, followed potentially by a multi-line body.

charliermarsh avatar Nov 29 '22 02:11 charliermarsh

Going to close for now but this is something I'd be open to exploring. E.g., it could be nice to automatically wrap docstring bodies apart from the summary line.

charliermarsh avatar Dec 11 '22 15:12 charliermarsh