Skip to content

Formatter: Uses space indentation in docstrings when using indent-style = "tab" #8430

@MichaReiser

Description

@MichaReiser

If I have indent-style set to "tab", when I run ruff format it is still converting indentation within docstring comments to be spaces, which then causes ruff check to fail on rule E101: Indentation contains mixed spaces and tabs

Before:

image

After:

image

Is there a format setting I can add to fix this? or is this a bug/intentional?

Originally posted by @1024Adam in #7310 (comment)

We can reproduce this behavior in our own tests:

def multiple_negatively_indented_docstring_lines():
"""a
b
c
d
e
"""

class IndentMeSome:
def doc_string_without_linebreak_after_colon(self):
"""This is somewhat strange
a
b
We format this a is the docstring had started properly indented on the next
line if the target indentation. This may we incorrect since source and target
indentation can be incorrect, but this is also an edge case.
"""

E101 has no special handling for docstring. It simply looks at every line and tests if the leading whitespace contains mixed spaces and tabs. Meaning, there can also be false positives if a multiline string contains leading whitespace that is a mix of spaces and tabs.

Metadata

Metadata

Assignees

Labels

formatterRelated to the formatter

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions