mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:53 +00:00
Fix blank-line docstring rules for module-level docstrings (#9878)
## Summary Given: ```python """Make a summary line. Note: ---- Per the code comment the next two lines are blank. "// The first blank line is the line containing the closing triple quotes, so we need at least two." """ ``` It turns out we excluded the line ending in `"""`, because it's empty (unlike for functions, where it consists of the indent). This PR changes the `following_lines` iterator to always include the trailing newline, which gives us correct and consistent handling between function and module-level docstrings. Closes https://github.com/astral-sh/ruff/issues/9877.
This commit is contained in:
parent
533dcfb114
commit
45937426c7
4 changed files with 32 additions and 22 deletions
|
@ -1634,12 +1634,13 @@ fn common_section(
|
|||
let line_end = checker.stylist().line_ending().as_str();
|
||||
|
||||
if let Some(next) = next {
|
||||
if context
|
||||
.following_lines()
|
||||
.last()
|
||||
.map_or(true, |line| !line.trim().is_empty())
|
||||
{
|
||||
if checker.enabled(Rule::NoBlankLineAfterSection) {
|
||||
if checker.enabled(Rule::NoBlankLineAfterSection) {
|
||||
let num_blank_lines = context
|
||||
.following_lines()
|
||||
.rev()
|
||||
.take_while(|line| line.trim().is_empty())
|
||||
.count();
|
||||
if num_blank_lines < 2 {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
NoBlankLineAfterSection {
|
||||
name: context.section_name().to_string(),
|
||||
|
@ -1657,13 +1658,13 @@ fn common_section(
|
|||
} else {
|
||||
// The first blank line is the line containing the closing triple quotes, so we need at
|
||||
// least two.
|
||||
let num_blank_lines = context
|
||||
.following_lines()
|
||||
.rev()
|
||||
.take_while(|line| line.trim().is_empty())
|
||||
.count();
|
||||
if num_blank_lines < 2 {
|
||||
if checker.enabled(Rule::BlankLineAfterLastSection) {
|
||||
if checker.enabled(Rule::BlankLineAfterLastSection) {
|
||||
let num_blank_lines = context
|
||||
.following_lines()
|
||||
.rev()
|
||||
.take_while(|line| line.trim().is_empty())
|
||||
.count();
|
||||
if num_blank_lines < 2 {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
BlankLineAfterLastSection {
|
||||
name: context.section_name().to_string(),
|
||||
|
|
|
@ -21,10 +21,9 @@ D413.py:1:1: D413 [*] Missing blank line after last section ("Returns")
|
|||
7 7 | Returns:
|
||||
8 8 | the value
|
||||
9 |+
|
||||
10 |+
|
||||
9 11 | """
|
||||
10 12 |
|
||||
11 13 |
|
||||
9 10 | """
|
||||
10 11 |
|
||||
11 12 |
|
||||
|
||||
D413.py:13:5: D413 [*] Missing blank line after last section ("Returns")
|
||||
|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue