Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
I was looking for a way to format single-line docstrings with ruff according to some projects internal guidelines, and found this isn't possible at the moment. The issue was raised before in ruff, so I decided it'd be worth it to see if I could get it in. Disclaimer: This MR contains LLM generated code, so treat with caution. It still is reviewed and tested by me, both inside the ruff container and in our codebase. Since it has already reformatted our codebase appropriately, I am happy with not merging it, but would like to give anyone the chance, if the code is up to par.
What happens in this MR:
I (and my project) actually prefer D213-style fixes, but by the lower number D212 takes precedence. Happy to flip it around.
The issue #4174 describes the use case well: some projects prefer multi-line docstrings everywhere to reduce churn when docstrings expand over time. This implements the inverse of D200 as a preview rule. The motivation in my personal projects was that it simply looks more homogeneous scanning through large files, and I find it more legible if all docstrings are formatted the same.
To achieve the behaviour, we now have:
OneLineDocstringShouldBeMultiLine(D219, preview)"""\nSummary.\n""""""Summary.\n"""Tested by:
INSTA_UPDATE=always cargo test -p ruff_linter pydocstyle::tests::rules -- D219INSTA_UPDATE=always cargo test -p ruff_linter pydocstyle::tests::multi_line_docstring_with_summary_on_second_lineThe fix is marked unsafe because it changes docstring formatting, which can affect docstring-parsing tools. The rule is added as preview and should require
--previewto enable