ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Enforcing docstring length (not the code snippets)

Open ma-sadeghi opened this issue 1 year ago • 5 comments
trafficstars

Is it possible to enforce docstring length (I know this possible for code snippets, but I mean the strings). Here's an example: Enforce docstring line length of 75:

def f(a, b):
	"""
	Very long long long long long long long long long long long long long long long long long description.

	Parameters
	----------
	a: int
		First number to add
	b: int
		Second number to add

	Returns
	-------
	int
		Another long long long long long long long long long long long long long long long long description.
	"""
def f(a, b):
	"""
	Very long long long long long long long long long long long long long long
    long long long description.

	Parameters
	----------
	a: int
		First number to add
	b: int
		Second number to add

	Returns
	-------
	int
		Another long long long long long long long long long long long long
        long long long long description.
	"""

ma-sadeghi avatar Feb 09 '24 13:02 ma-sadeghi

Hy @ma-sadeghi

Not yet. We want to add docstring (the comment content) formatting in the future and are also thinking about string formatting in general (automatically splitting or collapsing them) but this isn't supported today.

MichaReiser avatar Feb 09 '24 13:02 MichaReiser

@MichaReiser thanks for your quick reply. Looking forward to it!

ma-sadeghi avatar Feb 09 '24 18:02 ma-sadeghi

Not sure if this is also what you had in mind @ma-sadeghi, but I'd suggest not only convert this:

def foo():
    """
    Foo foo foo foo foo foo foo foo foo foo one two three four five six seven eight nine ten.
    """
    return "foo"

Into:

def foo():
    """
    Foo foo foo foo foo foo foo foo foo foo one two three four five six
    seven eight nine ten.
    """
    return "foo"

But also:

def foo():
    """
    Foo foo foo foo foo foo foo foo foo foo
    one two three four five six seven eight
    nine ten.
    """
    return "foo"

Into:

def foo():
    """
    Foo foo foo foo foo foo foo foo foo foo one two three four five six
    seven eight nine ten.
    """
    return "foo"

Peque avatar Apr 12 '24 15:04 Peque

@Peque Yep, that makes sense!

ma-sadeghi avatar Apr 17 '24 19:04 ma-sadeghi

+1 to this request

nataziel avatar Apr 23 '24 04:04 nataziel