Avoid treating newline-separated sections as sub-sections (#15311)

## Summary

Closes https://github.com/astral-sh/ruff/issues/15224.
This commit is contained in:
Charlie Marsh 2025-01-06 22:13:35 -05:00 committed by GitHub
parent 065274d353
commit e7248ee43e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 121 additions and 58 deletions

View file

@ -528,6 +528,22 @@ fn is_docstring_section(
}
}
// If the section has a preceding empty line, assume it's _not_ a subsection, as in:
// ```python
// def func(args: tuple[int]):
// """Toggle the gizmo.
//
// Args:
// args: The arguments to the function.
//
// returns:
// The return value of the function.
// """
// ```
if previous_line.map_or(false, |line| line.trim().is_empty()) {
return true;
}
// If the section isn't underlined, and isn't title-cased, assume it's a subsection,
// as in:
// ```python